Skip to content

Commit

Permalink
Check some optionals before unwrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
James Risberg committed Mar 13, 2016
1 parent 0ab691c commit 5088a08
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 6 additions & 4 deletions SplitStreamr/JoinSessionViewController.swift
Expand Up @@ -43,17 +43,19 @@ class JoinSessionViewController: UIViewController {
}

func didDisconnect(notification: NSNotification) {
dispatch_async(dispatch_get_main_queue(), { ()->Void in
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.activityIndicator.startAnimating();
self.manager.startAdvertising();
self.waitingLabel.text = "You were disconnected! Waiting to be invited to a new session.";
});
}

func updateData(notification: NSNotification) {
if let dataCount = notification.userInfo!["soFar"] {
let kilobytes: Int = Int(dataCount as! NSNumber)/1024;
self.downloadedLabel.text = "\(kilobytes) Kb";
if let userInfo = notification.userInfo {
if let dataCount = userInfo["soFar"] {
let kilobytes: Int = Int(dataCount as! NSNumber)/1024;
self.downloadedLabel.text = "\(kilobytes) Kb";
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions SplitStreamr/MusicPlayerViewController.swift
Expand Up @@ -70,7 +70,6 @@ class MusicPlayerViewController: UIViewController {
func queueChunkToPlay(song: Song, data: NSData) {
let path = NSTemporaryDirectory().stringByAppendingString("tmp.mp3");
data.writeToFile(path, atomically: true);
//NSURL *filepath = [NSURL fileURLWithPath:/*save file path*/];
let filePath = NSURL(fileURLWithPath: path);

let item = AVPlayerItem(URL: filePath);
Expand Down Expand Up @@ -104,7 +103,10 @@ class MusicPlayerViewController: UIViewController {
});

timer = NSTimer(timeInterval: 1.0, target: self, selector: "updateTime", userInfo: nil, repeats: true);
NSRunLoop.mainRunLoop().addTimer(timer!, forMode: NSRunLoopCommonModes);

if let _ = timer {
NSRunLoop.mainRunLoop().addTimer(timer!, forMode: NSRunLoopCommonModes);
}
}

func pause() {
Expand Down

0 comments on commit 5088a08

Please sign in to comment.