【问题标题】:sortUsingFunction and "void value not ignored as it ought to be"sortUsingFunction 和“不应忽略的无效值”
【发布时间】:2009-03-14 22:34:39
【问题描述】:

在我的目标 c 类中,我想像这样对数组进行排序:

NSArray *sorted = [unsortedArray sortUsingFunction: mySort context: NULL];

我的排序功能实现为:

NSInteger mySort(id one, id two, void *ctx) { return 1; }

当我构建程序时,编译器告诉我:

error: void value not ignored as it ought to be

现在我想我知道编译器想告诉我什么了:

“我不知道“mySort”到底是什么,所以我假设它返回“void”。哎呀,看起来你正试图将“void”分配给一个变量,不可以那个。再试一次。”

好的,编译器先生,我要告诉你什么让你知道函数原型是NSInteger mySort(id, id, void*)?我尝试将该行放在类头文件中,在“@interface”之前,之后,几乎所有地方,但我无法让它工作。

我必须在哪里/如何为我的排序函数声明函数原型?

提前非常感谢, 标记。

【问题讨论】:

    标签: objective-c


    【解决方案1】:

    sortUsingFunction: 是一个 NSMutableArray 方法,它对数组对象重新排序并且不返回值。看起来您正在寻找 sortedArrayUsingFunction:,这是一个 NSArray 方法,它返回已排序、自动释放的数组浅表副本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-04
      • 1970-01-01
      • 2011-11-10
      • 1970-01-01
      • 2015-12-23
      • 1970-01-01
      • 2022-09-28
      • 1970-01-01
      相关资源
      最近更新 更多