David van Dugteren
David van Dugteren

Reputation: 4109

When to specify 'public' explicitly in swift even if its not a framework?

I currently declare my properties in my main app like this:

public var thingA: String?
private var thingB: String?
private var thingC: String?

Should I omit the 'public' declaration within the main module as no other modules will need to use the thingA. such that it looks more like:

var thingA: String?
private var thingB: String?
private var thingC: String?

If we omit the 'public' here it simply means that if it was in a framework it could no longer be accessed from elsewhere, but in the main app/module, that simply isnt a concern so there's not only no point in using public but its arguably bad practice to be giving greater access than is required... (And maybe compiler related inefficiencies??)

Whats the agreed standard as I cant seem to find anything addressing this in documentation or stackoverflow?

Upvotes: 3

Views: 688

Answers (1)

Kamran
Kamran

Reputation: 15248

Access Controls are defined here. If no specific access control is defined it means it will have internal access control that allows access of that entity within the same module. Default access control is also internal and as mentioned in the link above, if you are working on a single target app, you can omit defining a specific access control(i.e, no need for public access control).

However, i believe you should always start with private access control and change it later as per the requirement.

Upvotes: 3

Related Questions