FROM : Jens Alfke
DATE : Mon Mar 03 07:32:30 2008
On 2 Mar '08, at 4:54 AM, Steven Degutis wrote:
> I think it's clear why [currentTrack
> isKindOfClass:[iTunesFileTrack class]] evaluates to true: in the
> previous line, you defined it as such, like this:
> iTunesTrack *currentTrack = [iTunes currentTrack];
> So obviously it is an iTunesTrack!
No. It could be an instance of a subclass of iTunesTrack, such as (in
this case) iTunesFileTrack. (That's true of any object-oriented
language.)
> Try this:
> iTunesFileTrack *currentTrack = [iTunesFileTrack currentTrack];
That won't even compile. You can't assign an iTunesTrack* to an
iTunesFileTrack*.
Moreover, since Obj-C is a dynamic language, it's more important what
the class of the object is at runtime, than what type the pointers are
defined as at compile time. You can change the type declarations, but
it won't affect what actual objects you get back at runtime.
—Jens
DATE : Mon Mar 03 07:32:30 2008
On 2 Mar '08, at 4:54 AM, Steven Degutis wrote:
> I think it's clear why [currentTrack
> isKindOfClass:[iTunesFileTrack class]] evaluates to true: in the
> previous line, you defined it as such, like this:
> iTunesTrack *currentTrack = [iTunes currentTrack];
> So obviously it is an iTunesTrack!
No. It could be an instance of a subclass of iTunesTrack, such as (in
this case) iTunesFileTrack. (That's true of any object-oriented
language.)
> Try this:
> iTunesFileTrack *currentTrack = [iTunesFileTrack currentTrack];
That won't even compile. You can't assign an iTunesTrack* to an
iTunesFileTrack*.
Moreover, since Obj-C is a dynamic language, it's more important what
the class of the object is at runtime, than what type the pointers are
defined as at compile time. You can change the type declarations, but
it won't affect what actual objects you get back at runtime.
—Jens
| Related mails | Author | Date |
|---|---|---|
| Hannes Petri | Mar 2, 02:28 | |
| Jonathan 'Wolf' Re… | Mar 2, 06:06 | |
| has | Mar 2, 13:05 | |
| Steven Degutis | Mar 2, 13:54 | |
| has | Mar 3, 00:02 | |
| Adam P Jenkins | Mar 3, 00:16 | |
| Adam P Jenkins | Mar 3, 00:40 | |
| has | Mar 3, 01:44 | |
| Jens Alfke | Mar 3, 07:32 | |
| has | Mar 3, 16:21 | |
| Steven Degutis | Mar 3, 16:27 | |
| Christopher Nebel | Mar 3, 21:22 | |
| has | Mar 3, 22:45 |






Cocoa mail archive

