覆盖Core Data属性的方法:isDeleted

时间:2015-01-21 23:33:50

标签: objective-c core-data

我想覆盖isDeleted中的NSManagedObject属性,因为它不会在我的应用程序中使用,并且在过去被意外使用时,引入了微妙的错误。考虑到这个目标,我正在考虑做类似以下的事情,并简单地让所有NSManagedObject类型继承自这个父类。这是我想要做的最佳方法吗?

@interface CustomManagedObject : NSManagedObject
@property (nonatomic, getter=isDeleted, readonly) BOOL deleted;
@end

@implementation CustomManagedObject

- (BOOL)isDeleted
{
    NSAssert(FALSE, @"Did you mean isDeleted, because that is not allowed...!");
}

// ....

@end

1 个答案:

答案 0 :(得分:3)

我认为以下内容更为优雅:

@interface CustomManagedObject : NSManagedObject
@property (nonatomic, getter=isDeleted, readonly) BOOL deleted __attribute__((unavailable));
@end

或者

@interface CustomManagedObject : NSManagedObject
@property (nonatomic, getter=isDeleted, readonly) BOOL deleted __attribute__((deprecated));
@end

试一试。