iphone – 由NSDate排序字典数组
发布时间:2020-12-15 01:50:09 所属栏目:百科 来源:网络整理
导读:我有一系列字典.在每个字典中,有一个关键的dateOfInfo(一个NSDate)和其他几个东西.我想通过每个字典dateOfInfo对数组进行排序,最新的是第一个结果. 我怎样才能做到这一点? 解决方法 您可以使用NSSortDescription进行排序,例如 NSSortDescriptor *sortDescri
我有一系列字典.在每个字典中,有一个关键的dateOfInfo(一个NSDate)和其他几个东西.我想通过每个字典dateOfInfo对数组进行排序,最新的是第一个结果.
我怎样才能做到这一点? 解决方法
您可以使用NSSortDescription进行排序,例如
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey: @"dateOfInfo" ascending: NO]; NSArray *sortedArray = [array sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]]; [sortDescriptor release]; 您也可以使用该方法 - (NSArray *)sortedArrayUsingFunction:(NSInteger (*)(id,id,void *))comparator context:(void *)context (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |