使用 Swift 将 UI 图片转至 ViewController

Segue UI Image to ViewController with Swift

我正在尝试将 uiimage 传递到我的 secondViewController,但是 运行 我的编码出现错误。我如何将 uiimage 连接到我的 secondViewController?

viewController.swift

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    if (segue.identifier == "test") {

       let destViewController : SecondViewController = segue.destinationViewController as SecondViewController

        destViewController.mainpictures = "background"
    }

第二视图控制器

class SecondViewController: UIViewController {

    var mainpictures = String ()

    @IBOutlet var mainImage: UIImageView!

    override func viewDidLoad() {

        self.mainImage.text = mainpictures

        super.viewDidLoad()
    }

写这段代码

if let image = UIImage(named: mainpictures) {
     self.mainImage.image = image
}

而不是这个

self.mainImage.text = mainpictures