Re: What are the limitations of Dot Syntax?
Re: What are the limitations of Dot Syntax?
- Subject: Re: What are the limitations of Dot Syntax?
- From: Chris Hanson <email@hidden>
- Date: Fri, 05 Dec 2008 18:40:00 -0800
On Dec 5, 2008, at 5:24 PM, Jerry Krinock wrote:
Thanks for the quick answer to Glenn and Bill. So now, knowing what
was legal, I was able to compile the following using "as many dots
as legally possible":
NSString* name = ((Bird*)[foo.bar.birds anyObject]).name ;
where
bar is an @property Bar* of Foo
birds is an @property NSSet* of Bar
name is an @property NSString* of Bird
Interestingly, it will not compile without the (Bird*) typecast.
As previously explained, that is expected. The return type of -[NSSet
anyObject] is (id), which you cannot use dot syntax from. By casting
the return value of -[NSSet anyObject] to (Bird *) you're giving the
compiler the information it needs to handle the .name construct.
Dot syntax compiles to objc_msgSend* just like bracket syntax does.
However, it must see either getter/setter declarations or an @property
declaration to know what selector to put in the objc_msgSend* that it
compiles to.
After all, it's perfectly legal to have Bird's definition of the name
property look something like
@property (nonatomic, copy, getter=BIRD_NAME,
setter=setBIRD_NAME) NSString *name;
You can then write "NSString *n = bird.name;" and the compiler will
generate an invocation of -BIRD_NAME.
-- Chris
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden