I'm sure this is stupid simple for all you seasoned guys out there, but for beginners it is tough!
I'm basically populating a table with a url that displays a json list.
So I have this in on top:
super.viewDidLoad()
get_data_from_url("http://www.example.com/my_jsonfile.php")
The following code works fine with a simple url without parameters:
func get_data_from_url(url:String)
{
let httpMethod = "GET"
let timeout = 15
let url = NSURL(string: url)
let urlRequest = NSMutableURLRequest(URL: url!,
cachePolicy: .ReloadIgnoringLocalAndRemoteCacheData,
timeoutInterval: 15.0)
let queue = NSOperationQueue()
NSURLConnection.sendAsynchronousRequest(
urlRequest,
queue: queue,
completionHandler: {(response: NSURLResponse!,
data: NSData!,
error: NSError!) in
if data.length > 0 && error == nil{
let json = NSString(data: data, encoding: NSASCIIStringEncoding)
self.extract_json(json!)
}else if data.length == 0 && error == nil{
println("Nothing was downloaded")
} else if error != nil{
println("Error happened = \(error)")
}
}
)
}
However how can I get my parameters in there? i.e.: the url should be:
http://www.example.com/my_jsonfile.php?the_date=2015-05-16&leaving=yes
get_data_from_url?