I can connect to a server synchronously with this code snippet in swift.
let URL: NSURL = NSURL(string: "http://someserver.com)!
let InfoJSON: NSData? = NSData(contentsOfURL: URL)
let JsonInfo: NSString = NSString(data:InfoJSON!, encoding: NSUTF8StringEncoding)!
let GameListAttributions: NSArray = NSJSONSerialization.JSONObjectWithData(InfoJSON!, options: .allZeros, error: nil)! as NSArray
This is only good for receiving information all at once, but how would I use a GET, POST, and PUT with Swift. No matter how much I search I can't find a good tutorial or example on how to execute these.
I created a function for a project that with the correct arguments you can post , put and get
This how to use the function:
Hope i helped. And sorry for my english
You can use the swift
NSMutableURLRequest
in order to make a POST request.Swift GET Example:
Documentation POST Example:
This is in objective-c but easy enough to convert to swift.
Documentation: https://developer.apple.com/library/prerelease/ios/documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html#//apple_ref/doc/uid/20001836-SW4