我想预测我的元素的名字。你能帮我吗
这是我的代码:
NSNumber *min = [NSNumber numberWithInteger:30];
NSNumber *max = [NSNumber numberWithInteger:100];
NSPredicate *predi;
predi = [NSPredicate predicateWithFormat:@"number BETWEEN %@", [NSArray arrayWithObjects:min, max, nil]];
NSArray *BoxWithPriceBetween = [array filteredArrayUsingPredicate:predi];
NSLog(@"Box %@", BoxWithPriceBetween);
这是我的结果:
2012-05-02 17:42:28.019 CoreDataTuto[2690:fb03] Box (
"<Phone: 0xba68790> (entity: Phone; id: 0xba687c0 <x-coredata:///Phone/t73E15BA0-90CA-4AEA-91B4-93BD8FD328737> ; data: {\n name = NAME6;\n number = 40;\n})",
"<Phone: 0xba64dc0> (entity: Phone; id: 0xba64df0 <x-coredata:///Phone/t73E15BA0-90CA-4AEA-91B4-93BD8FD328735> ; data: {\n name = NAME4;\n number = 33;\n})",
"<Phone: 0xba572a0> (entity: Phone; id: 0xba571e0 <x-coredata:///Phone/t73E15BA0-90CA-4AEA-91B4-93BD8FD328733> ; data: {\n name = NAME2;\n number = 33;\n})",
"<Phone: 0xba64d20> (entity: Phone; id: 0xba64d50 <x-coredata:///Phone/t73E15BA0-90CA-4AEA-91B4-93BD8FD328734> ; data: {\n name = NAME3;\n number = 43;\n})"
)
我希望得到所有预测的名字。
谢谢!
答案 0 :(得分:0)
我不确定我是否理解你的问题,但如果你想从每个对象中获取name属性,那么尝试这样的事情......
for (NSManagedObject *object in BoxWithPriceBetween) {
NSString *name = [object valueForKey:@"name"];
}
答案 1 :(得分:0)
最简单的方式
NSArray *names = [BoxWithPriceBetween valueForKey:@"name"];
来自NSArray文档
<强> valueForKey:强>
返回一个数组,其中包含调用valueForKey的结果:在每个数组的对象上使用键。
变量通常以小写字母开头,然后是驼峰。例如BoxWithPriceBetween
应为boxWithPriceBetween