这是我的问题:我有一个plist
里面有一些对象。这些对象有一些keys
像“年龄”、“性别”、“人”等。如果values
其中keys
适合我的if statement
,我把这个对象添加到我的array
.
然后,当我的数组最终充满了一些合适的对象时,我想再检查每个对象的一个键 - “minimumCost”,NSNumber
然后将对象从最便宜的对象排序到最昂贵的对象。我不知道该怎么做。你能给我一些想法、代码或解决方案吗?
这是我的代码:
-(NSMutableArray*)creatingList:(NSMutableArray *)array
{
NSDictionary *mainDictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"gifts" ofType:@"txt"]];
//---enumerate through the dictionary objects inside the rootDictionary
NSEnumerator *enumerator = [mainDictionary objectEnumerator];
id returnValue;
while ((returnValue = [enumerator nextObject]))
{
// Big if statement comes
if (([[returnValue valueForKey:@"sex"]isEqualToNumber:[NSNumber numberWithInt:sex]] ||
[[returnValue valueForKey:@"sex"]isEqualToNumber:[NSNumber numberWithInt:2]]) &&
[[returnValue valueForKey:@"person"]isEqualToString:person] &&
age >= [[returnValue valueForKey:@"minAge"] intValue] &&
age <= [[returnValue valueForKey:@"maxAge"] intValue])
{
[array addObject:[returnValue valueForKey:@"name"]];
}
}
for (int n = 0; n < [array count];n++)
{
// WHAT CODE SHOULD BE HERE ?
}
return array;
}
谢谢!