myImage.setImageWithUrl(myUrl, 2.0)
Make sure you whitelist the domains in the Info.plist
or allow all with:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
import WatchKit | |
public extension WKInterfaceImage { | |
public func setImageWithUrl(url:String, scale: CGFloat = 1.0) -> WKInterfaceImage? { | |
NSURLSession.sharedSession().dataTaskWithURL(NSURL(string: url)!) { data, response, error in | |
if (data != nil && error == nil) { | |
let image = UIImage(data: data!, scale: scale) | |
dispatch_async(dispatch_get_main_queue()) { | |
self.setImage(image) | |
} | |
} | |
}.resume() | |
return self | |
} | |
} |