Advertisement
Guest User

Untitled

a guest
Jun 25th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. var imageArray : [NSData] = []
  2. var imgIndex = 0
  3.  
  4. downloadFileFromURL(NSURL(string: self.posts.objectAtIndex(indexPath.row).valueForKey("enclosure") as! String)!, completionHandler:{(img) in
  5. dispatch_async(dispatch_get_main_queue(), { () -> Void in
  6. cell.sideImageView.image = img
  7.  
  8.  
  9. if indexPath.row == self.imgIndex{
  10. imageArray.insert(UIImageJPEGRepresentation(img, 0.75)!, atIndex: self.imgIndex)
  11. self.imgIndex++
  12. print("Image append with data")
  13. self.newsDefaults.setObject(imageArray, forKey: "image")
  14. }
  15.  
  16.  
  17. })
  18. })
  19.  
  20.  
  21. func downloadFileFromURL(url1: NSURL?,completionHandler: CompletionHandler) {
  22. // download code.
  23. if let url = url1{
  24. let priority = DISPATCH_QUEUE_PRIORITY_HIGH
  25. dispatch_async(dispatch_get_global_queue(priority, 0)) {
  26. let data = NSData(contentsOfURL: url)
  27. if data != nil {
  28. print("image downloaded")
  29. completionHandler(image: UIImage(data: data!)!)
  30. }
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement