Skip to content

Instantly share code, notes, and snippets.

@dennisschultz-db
Created February 4, 2016 21:00
Show Gist options
  • Save dennisschultz-db/c8b33b41a4198aaf6ec7 to your computer and use it in GitHub Desktop.
Save dennisschultz-db/c8b33b41a4198aaf6ec7 to your computer and use it in GitHub Desktop.
let picId = packet["pic_id"] as! String
let data = packet["data"] as! String
let pos = packet["pos"] as! Int
let total = packet["size"]as! Int
// Initialize picture if this is the first packet
if pos == 0 {
let timestamp = packet["pic_date"] as! Double
picture = Picture(name: picId, date: NSDate(timeIntervalSince1970: timestamp / 1000.0))
}
// finalize the picture and call completion handler if this is the last packet
if pos == total - 1 {
picture.addPacket(data, finalPacket: true)
pictureImage.image = picture.getImage()
} else {
picture.addPacket(data, finalPacket: false)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment