【问题标题】:Last part of string not getting inserted into coredata字符串的最后一部分未插入 coredata
【发布时间】:2011-07-14 16:59:56
【问题描述】:

我正在尝试在 Core Data 存储中插入字符串的最后一部分。我正在使用 NSXMLParser 获取字符串,但没有插入字符串的最后一部分。

for (NSMutableDictionary *fields in [delegate forecastConditions]) {
           // NSLog(@"got %@", fields);
            NSNumber*high=[fields objectForKey:@"high"];
            NSLog(@"the high is %@",high);
            NSManagedObjectContext *new=[self managedObjectContext];
            NSManagedObject *newNote;
            newNote=[NSEntityDescription insertNewObjectForEntityForName:@"Weather" inManagedObjectContext:new];
            [newNote setValue:[fields valueForKey:@"high"] forKey:@"high"];
            NSNumber *low=[fields objectForKey:@"low"];
            NSLog(@"the low is %@",low);
            [newNote setValue:[fields valueForKey:@"low"] forKey:@"low"];
            NSString*icon=[fields objectForKey:@"icon"];
            NSString *all=[icon lastPathComponent];

            NSLog(@" the icon is %@",all);
             [newNote setValue:[fields valueForKey:@"all"] forKey:@"condition"];
            NSString *string=[fields objectForKey:@"condition"];
            NSLog(@"the condition is %@",string);
            [newNote setValue:[fields valueForKey:@"string"] forKey:@"state"];

        }

【问题讨论】:

  • 什么newNote keyname out of high、low、condition or state,没有被设置?
  • fields 字典是否真的有一个 string 键或者是一个错字?

标签: objective-c ios4 core-data


【解决方案1】:

您的代码摘录太短,我们无法确定问题所在,但您将[fields objectForKey:][fields valueForKey:] 混合使用敲响了警钟。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-12
    • 1970-01-01
    • 2021-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-24
    相关资源
    最近更新 更多