Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var imageArray : [NSData] = []
- var imgIndex = 0
- downloadFileFromURL(NSURL(string: self.posts.objectAtIndex(indexPath.row).valueForKey("enclosure") as! String)!, completionHandler:{(img) in
- dispatch_async(dispatch_get_main_queue(), { () -> Void in
- cell.sideImageView.image = img
- if indexPath.row == self.imgIndex{
- imageArray.insert(UIImageJPEGRepresentation(img, 0.75)!, atIndex: self.imgIndex)
- self.imgIndex++
- print("Image append with data")
- self.newsDefaults.setObject(imageArray, forKey: "image")
- }
- })
- })
- func downloadFileFromURL(url1: NSURL?,completionHandler: CompletionHandler) {
- // download code.
- if let url = url1{
- let priority = DISPATCH_QUEUE_PRIORITY_HIGH
- dispatch_async(dispatch_get_global_queue(priority, 0)) {
- let data = NSData(contentsOfURL: url)
- if data != nil {
- print("image downloaded")
- completionHandler(image: UIImage(data: data!)!)
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement