-1

I have created a button for OSX in Swift language. I wish that button should download an image in my Mac. What code should I use for downloading that image?

Following is the code that I used:

@IBAction func buttonPressed(sender: NSButton) {
  buttonPresses+=1
  theLabel.stringValue = "You've pressed the button \n \(buttonPresses) times!"
  theButton.title = "Download\(buttonPresses)"
}
David Guyon
  • 2,759
  • 1
  • 28
  • 40
Mano Chitra R
  • 231
  • 1
  • 3
  • 13

1 Answers1

0

Alamofire is an easy way to download an image:

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
}
Yoichi Tagaya
  • 4,547
  • 2
  • 27
  • 38
  • i have used,but i didnt get yet – Mano Chitra R Mar 03 '15 at 09:47
  • First install Alamofire by Carthage or CocoaPods, then add `import Alamofire` at the beginning of your source file. `self.imageView` in sample code is just an example to assign the UIImage. Please replace `self.imageView` with anything else in your code. – Yoichi Tagaya Mar 03 '15 at 10:45
  • Try this: http://stackoverflow.com/questions/25817479/cannot-install-alamofire-in-new-xcode-project-no-such-module-alamofire – Yoichi Tagaya Mar 03 '15 at 12:36