Swift Extension 添加属性


class Company {
    
}

extension Company {
    
    private static var NAME_kEY: Void?
    
    var name: String {
        get {
            objc_getAssociatedObject(self, &Self.NAME_kEY) as! String
        }
        set {
            objc_setAssociatedObject(self, &Self.NAME_kEY, newValue, .OBJC_ASSOCIATION_COPY_NONATOMIC)
        }
    }
}


posted @ 2024-08-08 21:09  IT_IOS_MAN  阅读(6)  评论(0编辑  收藏  举报