我正在使用:
对NSSet
进行排序
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
[[testSet.questions allObjects] sortedArrayUsingDescriptors:descriptor]; // warning
但它会引起警告:
Incompatible pointer types sending 'NSSortDescriptor *__strong' to parameter of type 'NSArray *
答案 0 :(得分:3)
您正在传递一个预期数组的描述符,请尝试:
[testSet.questions allObjects] sortedArrayUsingDescriptors:@[descriptor]];
答案 1 :(得分:2)
你应该看到这种方法。它要求您将Array对象传递给它,而不是NSSortDescriptor对象。
[sortDescriptions sortedArrayUsingDescriptors:<#(NSArray *)#>]
因此您必须创建一个数组并将NSSortDescriptor对象放入其中。试试这个
NSArray *_sortArray = [[NSArray alloc] initWithObjects:descriptor, nil];
[testSet.questions allObjects] sortedArrayUsingDescriptors:_sortArray];
or
[testSet.questions allObjects] sortedArrayUsingDescriptors:@[descriptor]];
看看它是否有帮助:)
答案 2 :(得分:1)
NSSortDescriptor 。因此,您必须创建一个数组,然后在数组中添加描述符。现在你应该传递数组而不是 NSSortDescriptor :
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
NSArray *descriptorArray = [NSArray arrayWithObject:descriptor]
[[testSet.questions allObjects] sortedArrayUsingDescriptors:descriptorArray];
答案 3 :(得分:1)
试试这个:
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
[[testSet.questions allObjects] sortedArrayUsingDescriptors:[NSArray arrayWithObject:descriptor]];
希望这会有所帮助。