我有CoreData实体,其中包含 dateUpdated 属性(类型NSString
,格式为“2013-06-27”)。
当我想要读取此值时,它会返回 nil 。
Recipes *oldRecipe;
oldRecipe = [self getRecipeWithCode:i];
NSDateFormatter *dtFormatter = [[NSDateFormatter alloc] init];
[dtFormatter setDateFormat:@"yyyy-MM-dd"];
NSString *oDate = oldRecipe.dateUpdated;
//after this oDate is nil
NSDate *oldDate = [dtFormatter dateFromString:oDate];
我已经使用SQL Manager检查了实体中的值存在。
我怎样才能正确地做到这一点?
答案 0 :(得分:0)
正如讨论中所述,oldRecipe
对象是在
使用临时托管对象上下文的getRecipeWithCode
方法。
托管对象只能存在于其创建的上下文中。如果上下文已取消分配,则oldRecipe
将不会为nil,但访问其属性将始终返回nil。