Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions iOS/OperationQueues/OperationQueues/FaviconTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,32 @@ didSet {
var request = NSURLRequest(URL: self.url!)

// Display this text
self.textLabel.text = self.url?.host
self.textLabel?.text = self.url?.host

// Fire off the request, and give it a completion handler
// plus a queue to run on
NSURLConnection.sendAsynchronousRequest(request,
queue: self.operationQueue!,
completionHandler: {
(response: NSURLResponse!, data: NSData!, error: NSError!) in

// The 'data' variable now contains the loaded data;
// turn it into an image
var image = UIImage(data: data)

// Updates to the UI have to be done on the main queue.
NSOperationQueue.mainQueue().addOperationWithBlock() {

if data != nil {
// The 'data' variable now contains the loaded data;
// turn it into an image
var image = UIImage(data: data)

// Give the image view the loaded image
self.imageView.image = image

// The image view has probably changed size because of
// the new image, so we need to re-layout the cell.
self.setNeedsLayout()
// Updates to the UI have to be done on the main queue.
NSOperationQueue.mainQueue().addOperationWithBlock() {

// Give the image view the loaded image
self.imageView?.image = image

// The image view has probably changed size because of
// the new image, so we need to re-layout the cell.
self.setNeedsLayout()
}
}

})

}
Expand Down