0

我现在有:

 fetchRequest.resultType = NSDictionaryResultType;
    fetchRequest.propertiesToFetch = [NSArray arrayWithObject:[[entity propertiesByName] objectForKey:@"realLocationName"]];

这给了我这样的东西:

self.dict=
    (
            {
            realLocationName = "some where";
        },
            {
            realLocationName = somewhereelse;
        }
    )

我想从这本字典中的 cd 获取第二个属性值,但我不确定如何?

我尝试做这样的事情,但它只是用 locationID 覆盖 realLocationName

 fetchRequest.resultType = NSDictionaryResultType;
 fetchRequest.propertiesToFetch = [NSArray arrayWithObject:[[entity propertiesByName] objectForKey:@"realLocationName"]];
 fetchRequest.propertiesToFetch = [NSArray arrayWithObject:[[entity propertiesByName] objectForKey:@"locationId"]];
4

1 回答 1

0

在第 3 行:

fetchRequest.propertiesToFetch = [NSArray arrayWithObject:[[entity propertiesByName] objectForKey:@"locationId"]];

你已经覆盖了你在第二行设置的内容:

fetchRequest.propertiesToFetch = [NSArray arrayWithObject:[[entity propertiesByName] objectForKey:@"realLocationName"]];

您必须将一个数组设置为propertiesToFetch

NSDictionary *properties = [entity propertiesByName];
fetchRequest.propertiesToFetch = @[properties[@"realLocationName"], properties[@"locationId"]];

我使用文字来创建和访问NSArrayand NSDictionary

于 2013-10-09T16:28:31.507 回答