We're planting a tree for every job application! Click here to learn more

Difference Between Private and FilePrivate Swift

Muneeb Ali Arshad

26 Oct 2020

•

1 min read

Difference Between Private and FilePrivate Swift
  • 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.

Private Example

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. Fileprivate Example

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.

Did you like this article?

Muneeb Ali Arshad

I am an iOS developer with 4 years of experience, during this period I was involved in the development of such products as geolocation, music and video application, messengers, and social media apps and many more. I have experience across a wide variety of industries, including finance, travel, medicine, fashion. I am comfortable working as part of a team or individually and have an in-depth understanding of emerging technologies in new media.

See other articles by Muneeb

Related jobs

See all

Title

The company

  • Remote

Title

The company

  • Remote

Title

The company

  • Remote

Title

The company

  • Remote

Related articles

JavaScript Functional Style Made Simple

JavaScript Functional Style Made Simple

Daniel Boros

•

12 Sep 2021

JavaScript Functional Style Made Simple

JavaScript Functional Style Made Simple

Daniel Boros

•

12 Sep 2021

WorksHub

CareersCompaniesSitemapFunctional WorksBlockchain WorksJavaScript WorksAI WorksGolang WorksJava WorksPython WorksRemote Works
hello@works-hub.com

Ground Floor, Verse Building, 18 Brunswick Place, London, N1 6DZ

108 E 16th Street, New York, NY 10003

Subscribe to our newsletter

Join over 111,000 others and get access to exclusive content, job opportunities and more!

© 2024 WorksHub

Privacy PolicyDeveloped by WorksHub