Why am I getting an error?
The following line of code compiles with the following w开发者_如何学JAVAarning:
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?
(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]; }
精彩评论