I have the following code in my ViewController.swift
class:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
var newImage : UIImage?
let imgURL = NSURL(string : DemoURLs.photoURL)
func fetchImage(){
if let url = imgURL{
let imageData = NSData(contentsOfURL: url)
if imageData != nil{
newImage = UIImage( data: imageData! )
} else {
newImage = nil
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
imageView.image = newImage
}
}
The demoURLs.swift
file has a simple struct like this:
import Foundation
struct DemoURLs{
static var photoURL = " http://science-all.com/images/wallpapers/image/image-6.jpg "
}
When I run this in the simulator I get a plain white screen.