0

I Have a Web Server setup with an API that retrieves data from my database. It Returns JSON Data. I would like to be able to both GET and POST Data into my database from my iOS App. For example, Look up a persons name or login to the application. I'm a Beginner at this and any code or examples would help.

Thanks!

Blake

BlakeH
  • 685
  • 1
  • 8
  • 10

1 Answers1

3

You can see a detailed example of how to make HTTP calls (GET, POST, etc..) in swift here.

From the link above,

You can use NSURL, NSURLRequest and NSURLSession or NSURLConnection as you'd normally do in Objective-C. Note that for iOS 7.0 and later, NSURLSession is preferred.

Using NSURLSession

Initialize an NSURL object and an NSURLSessionDataTask from NSURLSession. Then run the task with resume().

var url = NSURL(string: "http://www.stackoverflow.com")

let task = NSURLSession.sharedSession().dataTaskWithURL(url) {(data, response, error) in
    println(NSString(data: data, encoding: NSUTF8StringEncoding))
}

task.resume()

For more detail, check the documentation for the NSURLConnectionDataDelegate protocol

Community
  • 1
  • 1
rageandqq
  • 2,221
  • 18
  • 24