A declaration cannot be both 'final' and 'dynamic' error in Swift 1.2

后端 未结 7 1377
Happy的楠姐
Happy的楠姐 2021-01-30 07:55

The declaration of value below

import Foundation

class AAA: NSObject {
    func test2() {
        self.dynamicType
    }
}
extension AAA {
    stat         


        
7条回答
  •  旧时难觅i
    2021-01-30 08:31

    This issue arises because Swift is trying to generate a dynamic accessor for the static property for Obj-C compatibility, since the class inherits from NSObject.

    If your project is in Swift only, rather than using a var accessor you can avoid the issue via the @nonobjc attribute in Swift 2.0:

    import Foundation
    
    class AAA: NSObject {}
    extension AAA {
        @nonobjc static let value = 111
    }
    

提交回复
热议问题