Skip to content

Instantly share code, notes, and snippets.

View jmfdz's full-sized avatar

Jose Maria Fernandez jmfdz

View GitHub Profile
@jmfdz
jmfdz / UIIMageViewExtensions.swift
Created November 27, 2016 09:38
Swift Extension for iOS: Load image from URL and put In UIImageView
import Foundation
import UIKit
extension UIImageView {
func downloadedFrom(url: URL, contentMode mode: UIViewContentMode = .scaleAspectFit) {
contentMode = mode
URLSession.shared.dataTask(with: url) { (data, response, error) in
guard
let httpURLResponse = response as? HTTPURLResponse, httpURLResponse.statusCode == 200,
let mimeType = response?.mimeType, mimeType.hasPrefix("image"),