Last active
April 10, 2016 21:55
-
-
Save qnoid/e9e4713a6ba15ed4603cbf441f88661b to your computer and use it in GitHub Desktop.
Just trying to push the limits of Swift to see what's possible. Trying to get an overall understanding of how code can be structured. Especially around object life cycles. Check the revisions for iterations over the design. Please don't write code like this, unless you know what you are doing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Imager | |
{ | |
unowned let session: Session | |
unowned let avatar: Avatar | |
func image(imageView: UIImageView) { | |
let download = self.session.download(self.avatar.image) { [weak imageView = imageView] (data, response, _) in | |
guard let _imageView = imageView else { | |
return | |
} | |
dispatch_async(dispatch_get_main_queue()) { | |
_imageView.image = UIImage(data: data!) | |
} | |
} | |
download.resume() | |
imageView.image = UIImage(named: self.avatar.defaultImage) | |
} | |
} | |
class Avatar { | |
let defaultImage = "avatar" | |
let image: String | |
init(image: String) { | |
self.image = image | |
} | |
lazy var imager: (session: Session) -> Imager = { | |
return { [unowned self] (session: Session) in | |
return Imager(session: session, avatar: self) | |
} | |
}() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment