I have the same problem, and I read wattson12 answer, then I solve another similar way. I do not know which is more efficient.
@IBAction func startIt (sender: AnyObject) {
startThrough();
};
// play button
func startThrough () {timer = NSTimer.scheduledTimerWithTimeInterval (1, target: self, selector: Selector ("updateTime"), userInfo: nil, repeat: true);
let pauseButton = UIBarButtonItem(barButtonSystemItem: .Pause, target: self, action: "pauseIt"); self.toolBarIt.items?.removeLast(); self.toolBarIt.items?.append( pauseButton ); }
func pauseIt () {
timer.invalidate(); let play = UIBarButtonItem(barButtonSystemItem: .Play, target: self, action: "startThrough"); self.toolBarIt.items?.removeLast(); self.toolBarIt.items?.append( play ); }
source share