ios给系统添加分类管理属性
生活随笔
收集整理的這篇文章主要介紹了
ios给系统添加分类管理属性
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
ios給系統添加分類管理屬性
swift 測試
import UIKit import ObjectiveCstruct MDTableConst{static let associatedKey = UnsafeRawPointer.init(bitPattern: "MDTableAccessoryKey".hashValue) } public extension UITableView{/*var manager:TableManager?{get{return objc_getAssociatedObject(self,MDTableConst.associatedKey!) as? TableManager}set{newValue?.bindTo(tableView: self)objc_setAssociatedObject(self, MDTableConst.associatedKey!, newValue, .OBJC_ASSOCIATION_RETAIN)}}*/ }oc
@interface UIViewController (AddPropertyInCategory) @property(nonatomic,assign)id test_assign; @property(nonatomic,strong)UIView *testView_Strong; @end #import "UIViewController+AddPropertyInCategory.h" #import <objc/runtime.h> static const void *test_assginKey = &test_assginKey; static const void *test_strongKey = &test_strongKey; @implementation UIViewController (AddPropertyInCategory) - (id)test_assign{return objc_getAssociatedObject(self, test_assginKey); }- (void)setTest_assign:(id)test_assign{objc_setAssociatedObject(self, test_assginKey, test_assign, OBJC_ASSOCIATION_ASSIGN); }- (UIView *)testView_Strong{return objc_getAssociatedObject(self, test_strongKey); } - (void)setTestView_Strong:(UIView *)testView_Strong{objc_setAssociatedObject(self, test_strongKey, testView_Strong, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } @end調用
#import "Test1VC.h" #import "UIViewController+AddPropertyInCategory.h"@implementation ViewController - (void)viewDidLoad {[super viewDidLoad];Test1VC *testVc = [[Test1VC alloc]init];UIView *iv = [[UIView alloc] init];iv.backgroundColor = UIColor.redColor;testVc.testView_Strong = iv; }總結
以上是生活随笔為你收集整理的ios给系统添加分类管理属性的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HEVC/H265 解码图表,请对照代码
- 下一篇: 嵌入式操作系统内核原理和开发