id & instancetype

From iOS 5, we have found a key word -> "instancetype", looks like it is same with the common type "id", so what's the different between them?

1.instancetype -> Related Result Types(相关返回类型), it means the variable of this type, it will include the class's info.

e.g. If 'NSArray''s class method 'array' return 'id' type, if user use invoke one method not in the NSArray, just like this:

[[NSArray array] methodNotInClass]; // **** no error

but if the method 'array' return 'instancetype' type, the code above will pop up error that without this method in the class, that's because the method 'array''s return value will include all the info of class.

2. 'instancetype' can not used as the type of method's params.

Reference:http://blog.csdn.net/cancer1617/article/details/21372353




你可能感兴趣的:(id & instancetype)