views:

28

answers:

1

The following line of code compiles with the following warning:

Code:

[[[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error] play];

Warning:

/Users/moshe/Development/iPhone/Apps/Live/iDecide/iDecideViewController.m:29:0 /Users/moshe/Development/iPhone/Apps/Live/iDecide/iDecideViewController.m:29: warning: multiple methods named '-play' found

What's going on here?

A: 

Hi

(completely new answer)

The init method is returning type id so you are going to get that message as there are multiple methods with that signature within the Cocoa frameworks

Do it in two steps (init then play) and it should vanish.

NSError *error = NULL;
AVAudioPlayer *myplayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
if(!error) { [myplayer play]; }
Warren Burton
Funny, because that signature was found in an Apple file...
Moshe
I actually copied it from a slide from a WWDC lecture.
Moshe
had a think about this. the init method is returning type id so you are going to get that message. Do it in two steps (init then play) and it should vanish
Warren Burton
Good call! If you can explain your comment a little better, you get a +1 too!
Moshe