我使用Mogenerator建设类我CoreData,我爱它基于关闭CoreData属性,像这样的_TAGUser
头文件的属性名称:添加到超类的结构在子类
extern const struct TAGUserAttributes {
__unsafe_unretained NSString *displayName;
__unsafe_unretained NSString *email;
} TAGUserAttributes;
@interface _TAGUser : NSManagedObject
@property (nonatomic, strong) NSString* displayName;
@property (nonatomic, strong) NSString* email;
@end
而这在实现文件:
const struct TAGUserAttributes TAGUserAttributes = {
.displayName = @"displayName",
.email = @"email",
};
@implementation _TAGUser
@end
在子类
TAGUser
现在,我添加了这个属性的头文件:
@interface TAGUser : _TAGUser {}
@property (strong, nonatomic, readonly) NSString *firstLetterOfDisplayName;
@end
而这款以实现文件:
@implementation TAGUser
- (NSString *)firstLetterOfDisplayName {
return ((self.displayName != nil && self.displayName.length > 0) ?
[self.displayName substringToIndex:1].uppercaseString :
nil);
}
@end
有没有一种方法,我可以扩展或增加结构TAGUserAttributes
让其他地方在我的代码,我可以在TAGUserAttributes.firstLetterOfDisplayName
呼吁国际志愿者组织,部分映射NSFetchedResultsController
等?
你不必检查:'self.displayName!= nil'。在发送到'nil'的Objective-C消息中返回0,所以如果'self.displayName'为'nil',则'self.displayName.length'将为0。 –