我有一个对象,例如“汽车”对象。在这个汽车对象中,我有另一个对象“轮胎”。这个轮胎对象有一些属性,其中之一是制造商。
我需要根据轮胎制造商对一系列汽车进行排序。
我知道如何根据带有描述符的汽车对象内部的属性对汽车对象进行排序。但是如何根据轮胎对象中的属性进行排序?
谢谢
最佳答案
排序描述符使用 KVC,因此您可以使用点语法根据轮胎制造商属性进行排序。像这样的东西:
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"tires.manufacturer" ascending:YES];
NSArray *sortedArray = [cars sortedArrayUsingDescriptors:@[sortDescriptor]];
有关 KVC 的更多信息,请查看此处:https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/KeyValueCoding/Articles/KeyValueCoding.html
关于iphone - 根据子对象的属性对对象进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16793661/