如何在使用Core Data时覆盖属性上的getter? [英] How can I override a getter on a property when using Core Data?

查看:166
本文介绍了如何在使用Core Data时覆盖属性上的getter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想能够覆盖我的一个核心数据模型上的字符串属性的getter,我需要找到该属性的值。

  @interface LabTest:NSManagedObject {
}
@property(nonatomic,retain)NSString * status;
@end

@implementation LabTest

@dynamic状态;

- (NSString *)status {
NSString * tempStatus = [super valueForKey:@status];
//做一些检查这里
return tempStatus;
}

@end

上述代码。我尝试了几个不同的东西,但我认为他们都结束了一个无限循环与程序崩溃的代码139。



什么是正确的方法

[self primitiveValueForKey:@ status] 而不是 [super valueForkey:@status]


I want to be able to override the getter on a string property on one of my core data models and inside the getter I need to find out what the value is for that property.

@interface LabTest : NSManagedObject {
}
@property (nonatomic, retain) NSString *status;
@end

@implementation LabTest

@dynamic status;

- (NSString *)status {
    NSString *tempStatus = [super valueForKey:@"status"];
    //do some checking here
    return tempStatus;
}

@end

The code above crashes the process. I have tried a few different things, but I think they all end up in an infinite loop with the program crashing with a code of 139.

What is the correct way to access a core data member in the getter like this?

解决方案

Have you tried [self primitiveValueForKey:@"status"] instead of [super valueForkey:@"status"]?

这篇关于如何在使用Core Data时覆盖属性上的getter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆