我的ViewController.swift
课程中包含以下代码:
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
}
}
demoURLs.swift
文件有一个像这样的简单结构:
import Foundation
struct DemoURLs{
static var photoURL = " http://science-all.com/images/wallpapers/image/image-6.jpg "
}
当我在模拟器中运行时,我得到一个纯白色的屏幕。
答案 0 :(得分:1)