我想覆盖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
答案 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
试一试。