代码之家  ›  专栏  ›  技术社区  ›  Moshe

为什么我会出错?

  •  0
  • Moshe  · 技术社区  · 14 年前

    以下代码行编译时出现以下警告:

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

    /Users/moshe/Development/iPhone/Apps/Live/iDecide/idecidevewcontroller.m:29:0 /Users/moshe/Development/iPhone/Apps/Live/iDecide/idecidevewcontroller.m:29:

    这是怎么回事?

    1 回复  |  直到 14 年前
        1
  •  0
  •   Warren Burton    14 年前

    init方法返回类型id,因此您将得到该消息,因为Cocoa框架中有多个方法具有该签名

    NSError *error = NULL;
    AVAudioPlayer *myplayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
    if(!error) { [myplayer play]; }