Quick access control for default initializer

The Swift Programming Language manual says:

"The initializer by default has the same access level as the type initializes."

Excerpt from: Apple Inc. "Fast programming language." interactive books. https://itun.es/us/jEUH0.l

and then he says:

β€œFor a type that is defined as open, the initializer is considered to be internal by default. If you want the public type to be initialized with an initializer with no arguments when used in another module, you must provide the public initializer without arguments yourself as part of the types.

Excerpt from: Apple Inc. "Fast programming language." interactive books. https://itun.es/us/jEUH0.l

Is the second statement not contrary to the first?

+6
source share
1 answer

Nope.

The second statement is only a supplement to the first.

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

Correct me if I am wrong.

+1
source

Source: https://habr.com/ru/post/974620/


All Articles