Objective-C: Property / instance variable in category

前端 未结 6 1430
清酒与你
清酒与你 2020-11-22 16:56

As I cannot create a synthesized property in a Category in Objective-C, I do not know how to optimize the following code:

@interface MyClass (Variant)
@prope         


        
6条回答
  •  被撕碎了的回忆
    2020-11-22 17:43

    Just use libextobjc library:

    h-file:

    @interface MyClass (Variant)
    @property (nonatomic, strong) NSString *test;
    @end
    

    m-file:

    #import 
    @implementation MyClass (Variant)
    
    @synthesizeAssociation (MyClass, test);
    
    @end
    

    More about @synthesizeAssociation

提交回复
热议问题