swift2 - Creating a soundboard app for iOS - stuck -


im extremely new ios development, , i'm trying make simple soundboard app.

i've watched various tutorials, , videos, can't seem code work in example. - maybe because video objective c or older version of swift - dont know.

https://www.youtube.com/watch?v=hzqcldd2x-a - seems easiest way i've found.

copying code:

import uikit import avfoundation  class viewcontroller: uiviewcontroller {      var sound01 = nsurl(fileurlwithpath: nsbundle.mainbundle().pathforresource("filename", oftype: "mp3")!)     var audioplayer = avaudioplayer()      override func viewdidload() {         super.viewdidload()         audioplayer = avaudioplayer(contentsofurl: sound01, error: nil)          // additional setup after loading view, typically nib.      }      override func didreceivememorywarning() {         super.didreceivememorywarning()         // dispose of resources can recreated.     }  } 

in version, doesn't errors: - yet in mine, get:

incorrect argument label in call (have 'contentsofurl:error:', expected 'contentsofurl:filetypehint:')

when use fix suggestion, becomes:

audioplayer = avaudioplayer(contentsofurl: sound01, filetypehint: nil) 

now error:

call can throw, not marked 'try' , error not handled

what doing wrong?

try replace line:

audioplayer = avaudioplayer(contentsofurl: sound01, error: nil)

with this:

audioplayer = try! avaudioplayer(contentsofurl: sound01!)


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -