@nonobjc static let test = "test"
有时我必须在方法之前编写@objc,所以在swift中使用@objc和@nonobjc.
任何人都可以帮我解决这个问题吗?
解决方法
When you use the @objc(name) attribute on a Swift class,the class is
made available in Objective-C without any namespacing. As a result,
this attribute can also be useful when migrating an archivable
Objective-C class to Swift. Because archived objects store the name of
their class in the archive,you should use the @objc(name) attribute
to specify the same name as your Objective-C class so that older
archives can be unarchived by your new Swift class.Conversely,Swift also provides the @nonobjc attribute,which 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. If an Objective-C method
is overridden by a Swift method that cannot be represented in
Objective-C,such as by specifying a parameter to be a variable,that
method must be marked @nonobjc.
总而言之,如果要在没有命名空间的情况下将Swift属性公开给Objective-C,请使用@objc.如果要保持属性可用并且只能在Swift代码中访问,请使用@nonobjc.