关于C#:NSComparator错误:不兼容的块指针类型初始化

Error with NSComparator: incompatible block pointer types initializing

这样做NSComparator:

1
2
3
4
NSComparator comparatore = ^NSComparisonResult(NSMutableDictionary *aDictionary, NSMutableDictionary *anotherDictionary) {
            return [[aDictionary objectForKey:@"Item"] localizedCaseInsensitiveCompare:[anotherDictionary objectForKey:@"Item"]];
    };
lista = [listaNonOrdinata sortedArrayUsingComparator:comparatore];

我收到此错误:
初始化'int(^)(struct NSMutableDictionary *,struct NSMutableDictionary *)'的不兼容块指针类型,预期为'NSComparator'

我已经在此站点和官方指南上阅读了有关此错误的信息,但尚未找到解决方案。

我已经尝试了一切,也许这里有人可以帮助我,或者有人知道如何以另一种方式做同样的事情。
谢谢!


NSComparator是一个期待两个id的块。 您需要将id作为参数类型,并在必要时在块中进行强制转换(在这种情况下,这是不必要的):

1
2
3
4
NSComparator comparatore = ^NSComparisonResult(id aDictionary, id anotherDictionary) {
    return [[aDictionary objectForKey:@"Item"] localizedCaseInsensitiveCompare:[anotherDictionary objectForKey:@"Item"]];
};
lista = [listaNonOrdinata sortedArrayUsingComparator:comparatore];