Difference Between Private and FilePrivate Swift
In this article, we will discuss Private and Fileprivate in iOS. This is my first article on medium I hope it will be helpful. Now, get started and we will deeply discuss both now:
Private:
Private variables and functions are only accessible in their scope only where they are created. For example, if we have a class and we declare the function or a variable private then it is accessible only in this class. if we try to access this in another class then we can not access it.
As you can see when we try to the private variable of the person class then an error appears saying: ‘name’ is inaccessible due to the ‘private’ protection level. Therefore if we want to access the name of the person class we have to make it public as we created an age variable. which is accessible and we can also assign a value to its object.
FilePrivate
Fileprivate variables and functions are accessible within the file they are created. But not in another file and also not in another class as private.
As you can see we created file private variable and it’s accessible in the same file easily but if we try to access in another file and class it will give an error.
Originally published on medium.com
Related Jobs
Related Articles
Related Issues
- Started
- 0
- 17
- Intermediate
- Submitted
- 1
- 0
- Intermediate
Get hired!
Sign up now and apply for roles at companies that interest you.
Engineers who find a new job through Python Works average a 15% increase in salary.
Start with GitHubStart with TwitterStart with Stack OverflowStart with Email