swift - Expression resolves to an unused function -


first of let me new programming. i'm trying add button when pressed plays music, , when pressed again music stops. ideally when button pressed third time music have reset. whilst trying achieve i'm getting error message "expression resolves unused function", new find online doesn't make sense me.

import uikit import avfoundation  class viewcontroller: uiviewcontroller {     @iboutlet weak var janitor: uiimageview!     var pianosound = nsurl(fileurlwithpath: nsbundle.mainbundle().pathforresource("c", oftype: "m4a")!)     var audioplayer = avaudioplayer()      override func viewdidload() {         super.viewdidload()          audioplayer = avaudioplayer(contentsofurl: pianosound, error: nil)         audioplayer.preparetoplay()     }      override func didreceivememorywarning() {         super.didreceivememorywarning()     }           @ibaction func pianoc(sender: anyobject) {          audioplayer.play()              if audioplayer.playing { audioplayer.stop} else {  audioplayer.play} } } 

swooping in here after martin r's comment ...

if audioplayer.playing { audioplayer.stop} else {  audioplayer.play} 

on line, not calling stop , play functions, accessing them. resolving unused function trying tell you have expression returning function type, never calling (audioplayer.stop , audioplayer.play expressions in question here).

to rid of error, , produce correct behavior, try calling functions.

if audioplayer.playing {      audioplayer.stop() } else {       audioplayer.play() } 

Popular posts from this blog