简体   繁体   English

如何从字典中获取2个属性

[英]How can I get 2 properties from my fetch in my dictionary

I right now I have: 我现在有:

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

which gives me something like this: 这给了我这样的东西:

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

I want to get a second attribute value from cd in this dictionary but im not sure how? 我想从这本词典中的cd获取第二个属性值,但我不确定如何?

I tried doing something like this but it just overwrites the realLocationName with locationID 我试图做这样的事情,但它只是用locationID覆盖了realLocationName

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

On the 3rd line: 在第三行:

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

you've overwritten what you'd set on the 2nd line: 您已经覆盖了第二行的设置:

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

You have to set one array as propertiesToFetch : 您必须将一个数组设置为propertiesToFetch

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

I've used literals for creating and accessing NSArray and NSDictionary . 我使用文字来创建和访问NSArrayNSDictionary

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从NetworkingService响应访问HomeViewController内部的User属性? - How can I access the User properties inside my HomeViewController from my NetworkingService response? 我如何从单个json值中提取字符串并将其快速附加到我的标签中(使用alamofire) - how can I fetch a string from a single json value and append it to my label in swift (using alamofire) 如何快速从地图视图上的特定点获取经度和纬度? - how can I fetch the longitude and latitude from a specific point on my mapview in swift? 如何从iOS应用程序中获取列表并要求Siri发音该列表 - How can I fetch list from my iOS application and ask Siri to pronounce the list 如何在我的应用程序中从Xcode获取环境变量 - How can I get an environment variable from Xcode in my app 如何在函数外部更改字典中的Double值? - How can I change the Double value in my dictionary outside the function? 我怎么才能只阅读我的字典中的一个值? - how can I read only one value of my dictionary? 如何从SSL属性中删除已弃用的API警告 - How can I remove the deprecated API warnings from my SSL properties 如何使用此配置访问我的UINavigationBar属性? - How can I access my UINavigationBar properties with this config? 我无法发布字典值 - I can't post my dictionary values
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM