Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift's access control for default initializer

In Swift Programming Language guide, it says:

“The default initializer has the same access level as the type it initializes.”

Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/us/jEUH0.l

and then it says:

“For a type that is defined as public, the default initializer is considered internal. If you want a public type to be initializable with a no-argument initializer when used in another module, you must provide a public no-argument initializer yourself as part of the type’s definition.”

Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/us/jEUH0.l

Isn't the second statement contradictory with the first?

like image 433
Boon Avatar asked Aug 31 '14 19:08

Boon


People also ask

What is default access control in Swift?

internal is the default access level. Internal classes and members can be accessed anywhere within the same module(target) they are defined. You typically use internal access when defining an app's or a framework's internal structure.

How many types of access modifiers we can use in Swift which one is default?

Swift provides five different access levels for entities within your code. These access levels are relative to the source file in which an entity is defined, and also relative to the module that source file belongs to.

What are the access specifiers in Swift?

Access specifier is keyword which helps in Access control of code block. Access control restricts access to the parts of your code from code in other source files and modules. Encapsulation is one pillar of Object Oriented Programming and access specifiers helps in encapsulating.

What is access level in Swift?

Three different access levels are provided by Swift 4 language. They are Public, Internal and Private access. Enables entities to be processed with in any source file from their defining module, a source file from another module that imports the defining module.


1 Answers

Nope.

The second statement is just a complementary note on the first one.

I think it wants to say that the public-access type is a special case: the access level of the default initializer for public-access case is internal. If one want to provide a public-access default initializer, then he needs to do it explicitly.

Correct me if I'm wrong.

like image 65
Windor C Avatar answered Oct 15 '22 07:10

Windor C