When @objc and @nonobjc write before method and variable in swift?

后端 未结 3 667
时光说笑
时光说笑 2021-02-04 06:28

When I declare static parameter in extension of class then I have to write @nonobjc before variable like

 @nonobjc static let test = \"test\"

a

3条回答
  •  甜味超标
    2021-02-04 07:29

    Here you can find more details in this Swift Documentation : InteractingWithObjective-C

    As an answer of your question, overview from attached link is as below.

    @objc : You can use attribute to change the name of a class, property, method, enumeration type, or enumeration case declaration in your interface as it’s exposed to Objective-C code.

    Example : if the name of your Swift class contains a character that isn’t supported by Objective-C, you can provide an alternative name to use in Objective-C.

    @nonobjc : It makes a swift declaration unavailable in Objective-C. You can use it to resolve circularity for bridging methods and to allow overloading of methods for classes imported by Objective-C.

提交回复
热议问题