Skip to content

Instantly share code, notes, and snippets.

@qnoid
Last active April 10, 2016 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qnoid/e9e4713a6ba15ed4603cbf441f88661b to your computer and use it in GitHub Desktop.
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.
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