NSComparisonResult和NSComparator - 它们是什么? [英] NSComparisonResult and NSComparator - what are they?

查看:128
本文介绍了NSComparisonResult和NSComparator - 它们是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是 NSComparisonResult NSComparator

我见过其中一个类型定义,类似于:

I've seen one of the type definitions, something like that:

typedef NSComparisonResult (^NSComparator)(id obj1, id obj2);

与函数指针有什么不同吗?

Is it any different from a function pointer?

另外,我甚至无法猜出 ^ 符号的含义。

Also, I can't even guess what the ^ symbol means.

推荐答案

^ 表示块类型,在概念上类似于函数指针。

^ signifies a block type, similar in concept to a function pointer.

typedef NSComparisonResult (^NSComparator)(id obj1, id obj2);
//          ^                      ^                ^
//   return type of block      type name       arguments

这意味着类型 NSComparator 是一个,它接收两个类型为 id 调用 obj1 obj2 ,并返回 NSComparisonResult

This means that the type NSComparator is a block that takes in two objects of type id called obj1 and obj2, and returns an NSComparisonResult.

具体 NSComparator 基础数据类型参考

要了解有关C块的更多信息,请查看此ADC文章阻止编程主题

And to learn more about C blocks, check out this ADC article Blocks Programming Topics.

示例:

NSComparator compareStuff = ^(id obj1, id obj2) {
   return NSOrderedSame;
};

NSComparisonResult compResult = compareStuff(someObject, someOtherObject);

这篇关于NSComparisonResult和NSComparator - 它们是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆