开发者

Why am I getting an error?

开发者 https://www.devze.com 2023-01-12 02:21 出处:网络
The following line of code compiles with the following w开发者_如何学JAVAarning: Code: [[[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error] play];

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]; }
0

精彩评论

暂无评论...
验证码 换一张
取 消