xcode6.1 - How to fix error in AVAudioPlayer init using swift -



xcode6.1 - How to fix error in AVAudioPlayer init using swift -

this code , sound beingness played, after updated xcode 6.1 error

extra argument 'contentsofurl' in call

var alertsound = nsurl(fileurlwithpath: nsbundle.mainbundle().pathforresource("sound", oftype: "aiff")!) //println(alertsound); // removed deprecated utilize of avaudiosessiondelegate protocol avaudiosession.sharedinstance().setcategory(avaudiosessioncategoryplayback, error: nil) avaudiosession.sharedinstance().setactive(true, error: nil) var error:nserror?; audioplayer = avaudioplayer(contentsofurl: alertsound, error: &error); // error audioplayer.preparetoplay();

how can prepare error , xcode stop showing it

in line:

audioplayer = avaudioplayer(contentsofurl: alertsound, error: &error)

the problem alertsound optional, because nsurl(fileurlwithpath:) can homecoming nil. need disclose it:

audioplayer = avaudioplayer(contentsofurl: alertsound!, error: &error)

that allow code compile. better, however, check explicitly whether alertsound nil before that! if is nil, unwrapping straight cause crash.

swift xcode6.1

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -