设为首页 加入收藏

TOP

Objective-C instancetype关键字
2017-10-12 09:45:56 】 浏览:1240
Tags:Objective-C instancetype 关键字

 instancetype是clang 3.5开始,clang提供的一个关键字 

表示某个方法返回的未知类型的Objective-C对象

instancetype会告诉编译器当前的类型,这点和NSObject *类似,但id对于编译器却是无类型的,调用任何方法不会给出错误提示

 

instancetype类型:

(1)instancetype会让编译器检查实例化对象的准确类型 
(2)instancetype只能用于返回类型,不能当做参数使用

instancetype & id的比较:

(1) instancetype在类型表示上,跟id一样,可以表示任何对象类型

(2) instancetype只能用在返回值类型上,不能像id一样用在参数类型上

(3) instancetype比id多一个好处:编译器会检测instancetype的真实类型

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇比较两个日期之间相差天数 月数 .. 下一篇NSProxy

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目