Macos 如何使用swift语言在OSX中下载图像

Macos 如何使用swift语言在OSX中下载图像,macos,Macos,我用Swift语言为OSX创建了一个按钮。我希望那个按钮能在我的Mac电脑上下载一个图像。 我应该使用什么代码下载该图像 以下是我使用的代码: @IBAction func buttonPressed(sender: NSButton) { buttonPresses+=1 theLabel.stringValue = "You've pressed the button \n \(buttonPresses) times!" theButton.title = "Download\

我用Swift语言为OSX创建了一个按钮。我希望那个按钮能在我的Mac电脑上下载一个图像。 我应该使用什么代码下载该图像

以下是我使用的代码:

@IBAction func buttonPressed(sender: NSButton) {
  buttonPresses+=1
  theLabel.stringValue = "You've pressed the button \n \(buttonPresses) times!"
  theButton.title = "Download\(buttonPresses)"
}
是下载图像的简单方法:

Alamofire.request(.GET, url).response() { request, response, data, error in
    var image: UIImage?
    if nil == error {
        if let imageData = data as? NSData {
            image = UIImage(data: imageData)
        }
    }
    self.imageView.image = image
}

我用过,但我没有得到yetFirst安装Alamofire由迦太基或CocoaPods,然后添加
导入Alamofire
在您的源文件的开头<示例代码中的code>self.imageView只是分配UIImage的一个示例。请用代码中的任何其他内容替换
self.imageView
。请尝试以下操作: