iphone – 使用NSSortDescriptor的非常自定义的订单
发布时间:2020-12-14 17:45:35 所属栏目:百科 来源:网络整理
导读:假设我有不同状态的对象.状态从0到2.我需要使用NSSortDescriptor以这种方式对它们进行排序: 1 2 0 有什么建议? 解决方法 像这样(未经测试): descriptor = [[[NSSortDescriptor alloc] initWithKey:@"status" ascending:YES selector:@selector(customStat
假设我有不同状态的对象.状态从0到2.我需要使用NSSortDescriptor以这种方式对它们进行排序:
1 2 0 有什么建议? 解决方法
像这样(未经测试):
descriptor = [[[NSSortDescriptor alloc] initWithKey:@"status" ascending:YES selector:@selector(customStatusCompare:)] autorelease]; @interface NSNumber (CustomStatusCompare) - (NSComparisonResult)customStatusCompare:(NSNumber*)other; @end @implementation NSNumber (CustomStatusCompare) - (NSComparisonResult)customStatusCompare:(NSNumber*)other { NSAssert([other isKindOfClass:[NSNumber class]],@"Must be a number"); if ([self isEqual:other]) { return NSOrderedSame; } else if (... all your custom comparison logic here ...) } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读