generics - <ObjectType> in Objective-C -
in nsarray.h saw interface this
@interface nsarray<objecttype>
what significance of <objecttype>
?
that apple using lightweight generics. full @interface
declaration in xcode 7.3.1 looks this:
@interface nsarray<__covariant objecttype> : nsobject <nscopying, nsmutablecopying, nssecurecoding, nsfastenumeration>
objecttype
placeholder used represent generic argument pass compiler knows reference them. different using nsobject *
because objecttype
id
, can refer non-objective-c pointer types such corefoundation objects.
for example, if wanted create class mocks array specific class, @interface myarray<myclass *>
.
you declare array of strings nsarray<nsstring *>
.
see this article on objective-c generics more information.
Comments
Post a Comment