目标c中的数组排序错误

Umu*_*mut 1 objective-c ios

我在下面的NSDictionary中有4个值,分别是1000,640,80和0,它正确地对非零值进行排序,但它总是给出0大于所有其他值,如(降序):0,1000,640,80这里是代码:

    NSMutableDictionary *dict = [[self model] stateFromDocumentNamed:@"state"];
    NSArray *values=[dict allValues];
    NSMutableArray *mutvalues = [(NSArray*)values mutableCopy];
    [mutvalues sortUsingSelector:@selector(compare:)];
    values=[[values reverseObjectEnumerator] allObjects];
    NSLog(@"%@",mutvalues);
Run Code Online (Sandbox Code Playgroud)

Wai*_*ain 5

据推测,您正在比较包含数字的字符串.要使排序按预期使用数字,您将需要使用该NSNumericSearch选项(在方法中compare:options:,可能与之一起使用sortedArrayUsingComparator:).