Re: Why can't I name a property `tag'?
Re: Why can't I name a property `tag'?
- Subject: Re: Why can't I name a property `tag'?
- From: Jens Alfke <email@hidden>
- Date: Thu, 10 Jul 2008 08:40:53 -0700
On 10 Jul '08, at 8:19 AM, an0 wrote:
However, if you don't know what exact type of Cocoa I am, how could
you call me BlackCocoa so surely?
Can we stop using confusing metaphors and just talk about OOP? :-p
When the compiler parses a message-send expression ("[....]") it tries
to figure out which declared method is being invoked. The most
important reason for this is that it needs to know the return type of
the method, because that can affect the machine code that's generated
for the call.
If the receiver of the expression is typed as "id", i.e. with no
class, the compiler has no clues about what class to look for matching
methods in. So it looks in any @interface blocks that it's already
seen (i.e. ones in all #imported headers). If it finds one matching
method, it uses it. If it finds more than one method, and the return
types differ, then the situation is ambiguous … so it emits a warning.
The short answer to your question, then, is that the compiler has to
decide what method is being used, because that determines what machine
code to generate. This is an ugly side effect of the fact that
Objective-C compiles into native code and not some abstract bytecode
like Java or Python. It's part of the price you pay as a developer for
creating apps that run fast.
—Jens
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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