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

后端 未结 7 1373
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
    慢半拍i (楼主)
    2021-01-30 08:17

    You can mark it as private to prevent this error. If you want to expose it, you can wrap it in a public function:

    extension AAA {
    
        private static let value = 111
    
        public func getDatValue() -> Int {
            return AAA.value
        }    
    }
    

    In my case, I only referenced the property in the extension itself, so there was no need to expose it.

提交回复
热议问题