Arrays 按数组中字典中嵌套的字符串对数组进行排序
所以我有一个相当复杂的plist系统。下面是显示数据结构的图像Arrays 按数组中字典中嵌套的字符串对数组进行排序,arrays,sorting,dictionary,nsstring,plist,Arrays,Sorting,Dictionary,Nsstring,Plist,所以我有一个相当复杂的plist系统。下面是显示数据结构的图像 是否可以按嵌套在这些字典中的键为“name”的字符串对整个“Staff”数组进行排序?字符串当然会有值 您需要先找到员工NSArray,然后像往常一样使用NSSortDescriptor对其进行排序 这是我的密码 NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Contacts" ofType:@"plist"]; NSDictionary *conta
是否可以按嵌套在这些字典中的键为“name”的字符串对整个“Staff”数组进行排序?字符串当然会有值 您需要先找到员工
NSArray
,然后像往常一样使用NSSortDescriptor
对其进行排序
这是我的密码
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Contacts" ofType:@"plist"];
NSDictionary *contacts = [NSDictionary dictionaryWithContentsOfFile:plistPath];
NSArray *staff = [contacts objectForKey:@"Staff"];
NSSortDescriptor *sortDesc = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
NSLog(@"%@", [staff sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDesc]]);
谢谢您需要先找到员工
NSArray
,然后像往常一样使用NSSortDescriptor
对其进行排序
这是我的密码
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Contacts" ofType:@"plist"];
NSDictionary *contacts = [NSDictionary dictionaryWithContentsOfFile:plistPath];
NSArray *staff = [contacts objectForKey:@"Staff"];
NSSortDescriptor *sortDesc = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
NSLog(@"%@", [staff sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDesc]]);
谢谢你的回答!我刚才想出来了,但还是感谢你回答我/谢谢你的回答!我刚才想出来了,但还是感谢你回答我/雅各布