Will the quick distribution markup be publicly available to change the property in the extension so that it is implicit public or internal?

So, in the Apple documentation:

Any type members added to the extension have the same default access level, since type members declared in the original type will be expanded. If you extend an open or internal type, any new type members you add will have a default access level of internal .

Providing a subclass of the UIView extension:

extension UIViewSubClass
{
    var helloWorld : String {
        get {
            return "helloWorld"
        }
    }
}

This will mean helloWorldas internal, I have no problem, and I do not see it in my Objective-C project.

However, if I declare the extension publicly available:

public extension UIViewSubClass
{
    var helloWorld : String {
        get {
            return "helloWorld"
        }
    }
}

helloWorld apprears Objective-C, , .

, Apple , ?

, , - .

public class SomePublicClass {          // explicitly public class
    public var somePublicProperty = 0    // explicitly public class member
    var someInternalProperty = 0         // implicitly internal class member
    private func somePrivateMethod() {}  // explicitly private class member
}

public , . .

- , , - ? 2.1 Xcode 7.2

+4
1

.. , ( public, ) .

, / .. ( ). , , .


Swift. Swift Language Guide - - .

, :

( , ) , .

, , : , , .

, :

, , , . , , , , , . , , . , .

(, private extension), , . .

. , UIViewSubClass public ( , se ):

/* no access level modifier: default access level will be 'internal' */
extension UIViewSubClass
{
    // default access level used: internal
    var helloWorld : String { 
        get {
            return "helloWorld"
        }
    }
}

// modify default access level to public
public extension UIViewSubClass
{
    // default access level used: public
    var helloWorld : String { 
        get {
            return "helloWorld"
        }
    }
}

, helloWorld public extension ... internal, . , .

, , public Swift. , :

  • UISubViewClass internal private, public extension ... .
  • UISubViewClass public, public extension , public.

, , , , , ( ) : public private internal s public`.

class MyImplicitlyInternalClass {
    private var myExplicitlyPrivateVar = 0
    var myImplicitlyInternalVar = 0
    public var myExplicitlyPublicVar = 0 // warning, see (Note 1) below
        // redundant 'public': can never be accessed publicly
        // myExplicitlyPublicVar will behave as 'internal'
}

public extension MyImplicitlyInternalClass { // error, see (Note 2)
    var myNewVarIsInternal : Int { get { return 0 } } 
}
/* (Note 1) Compile type warning:
        "Declaring a public var for an internal class."

   (Note 2) Compile time error:
        "Extension of internal class cannot be declared public." 

   Summary: in theory, these two above are the same type of
            'faults', but only the latter is flagged as and error. */

, , , .. internal extension ... public private extension internal.

+3

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


All Articles