فرز nsarray من خلال علاقة القيمة الرئيسية التي هي مستويين عميق
-
02-10-2019 - |
سؤال
لديّ nsarray من كائنات uilocalnotification التي أحتاج إلى الفرز وفقًا لمفتاح داخل خاصية userInfo الخاصة بـ UilocalNotification ، والتي هي nsdictionary. أعرف كيفية فرز NSArrays بقيمة بعمق مستوى واحد ، على سبيل المثال ، مفتاح ضمن مجموعة من NSDictionaries ، لكن مستويين عميقان لقد فقدت. أريد أن أفعل شيئًا كهذا هو psuedo-code:
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"userInfo.personName" ascending:YES];
//the personName key within the userInfo NSDictionary property of a given UILocalNotification
NSArray *sortDescriptors = [[[NSArray alloc] initWithObjects:&sortDescriptor count:1] autorelease];
NSMutableArray *sortedArray = [[[NSMutableArray alloc] initWithArray:[[UIApplication sharedApplication] scheduledLocalNotifications]] autorelease];
[sortedArray sortUsingDescriptors:sortDescriptors];
المحلول
هل جربت الرمز الخاص بك؟ وثيقة Apple (هنا) يقول إنه يقبل المسارات الرئيسية ، وليس فقط المفاتيح.
لا تنتمي إلى StackOverflow