protocols - Use of TypeName<protocol_name> in variable declaration in Objective-C -


usually when comes declare variable protocol it's done follows:

id<protocol_name> variable; 

but i've seen don't understand. compiler allows define things like:

nsstring<protocol_name> *variable; 

in fact assigning other "plain" nsstring variable cause compiler warn , you'll need cast it.

i've seen in jsonmodel , framework uses "annotate" properties.

but, apart intended for? benefits?

thanks.

benefits variable can work nsstring* , id<protocol_name>. may need interfaces , don't need type casting.

"plain" nsstring not conform protocol "protocol_name" , compiler doesn't allows that.

but can make nsstring conform protocol categories:

@interface nsstring(protocol_name) < protocol_name > @end 

actually nsstring<protocol_name> bad example, because can't subclass nsstring.

with other classes can subclass, can implement protocol in childs.


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -