setting new properties in category interface/implementation

后端 未结 7 1490
醉梦人生
醉梦人生 2020-12-03 03:42

Ok, so I have this, but it wont work:

@interface UILabel (touches)

@property (nonatomic) BOOL isMethodStep;

@end


@implementation UILabel (touches)

-(BOO         


        
7条回答
  •  情歌与酒
    2020-12-03 04:03

    It seems as if since Xcode 7 (7.0.1, 7A1001), properties are supported in categories. I noticed that Xcode generates categories now for Core Data subclasses.

    For example, I got the files:

    Location+CoreDataProperties.h

    #import "Location.h"
    
    NS_ASSUME_NONNULL_BEGIN
    
    @interface Location (CoreDataProperties)
    
    @property (nullable, nonatomic, retain) NSNumber *altitude;
    @property (nullable, nonatomic, retain) NSNumber *latitude;
    @property (nullable, nonatomic, retain) NSNumber *longitude;
    
    @end
    
    NS_ASSUME_NONNULL_END
    

    Location+CoreDataProperties.m

    #import "Location+CoreDataProperties.h"
    
    @implementation Location (CoreDataProperties)
    
    @dynamic altitude;
    @dynamic latitude;
    @dynamic longitude;
    
    @end
    

    So looks like properties in categories might work now. I haven't tested on non-Core Data classes.

    What I've noticed is that they do include the category file back into the original class:

    Location.h

    @interface Location : NSManagedObject
    
    @end
    
    #import "Location+CoreDataProperties.h"
    

    This allows the original class to edit the properties specified by the category.

提交回复
热议问题