Subject: Strange cast for CFURLRef

Hello all,

I've been going through the SpeakHere sample code from the iPhone SDK
and trying to repurpose some of the code for what I'm working on.

I ran into something I don't quite understand and was hoping to get
some enlightenment. There's a method defined on AudioPlayer that goes
like this:

- (id) initWithURL: (CFURLRef) fileURL;

In the code I'm using to call it I have the following:

NSString *thePath = [[NSBundle mainBundle] pathForResource:@"MySound"
CFURLRef fileURL = CFURLCreateWithFileSystemPath (


(CFStringRef) thePath,



AudioPlayer *thePlayer = [[AudioPlayer alloc] initWithURL: (NSURL *)fileURL];

The question I have is on the line:

AudioPlayer *thePlayer = [[AudioPlayer alloc] initWithURL: (NSURL *)fileURL];

Why does fileURL have to be cast to NSURL * when initWithURL wants a
CFURLRef? Without that cast, I get a compile error about incompatible

It appears the reason for the CFURLRef is that's what the lower level
Sound Toolbox calls need, but why all the casting at the higher levels
when it could just be a NSURL until the time when the toll free bridge
cast to CFURLRef is needed for those calls?

Any insight would be greatly appreciated.


Cocoa-dev mailing list (Cocoa-dev@xxxxxxxxxxxxxxx)

r> Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)

Help/Unsubscribe/Update your Subscription:

This email sent to maillists@xxxxxxxxx