فرز nsarray من خلال علاقة القيمة الرئيسية التي هي مستويين عميق

StackOverflow https://stackoverflow.com/questions/3169588

سؤال

لديّ 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 (هنا) يقول إنه يقبل المسارات الرئيسية ، وليس فقط المفاتيح.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top