Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 按数组中字典中嵌套的字符串对数组进行排序_Arrays_Sorting_Dictionary_Nsstring_Plist - Fatal编程技术网

Arrays 按数组中字典中嵌套的字符串对数组进行排序

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

所以我有一个相当复杂的plist系统。下面是显示数据结构的图像


是否可以按嵌套在这些字典中的键为“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]]);

谢谢你的回答!我刚才想出来了,但还是感谢你回答我/谢谢你的回答!我刚才想出来了,但还是感谢你回答我/雅各布