I'm entirely new to development in Swift or networking. I'm trying to throw something simple together that query a URL:
I'm trying to write a simple program, where I have three buttons, and each time a button is tapped, I send data to the data.sparkfun.com data stream storing service where it will store my variable "test_value"
I need to query this URL:
http://data.sparkfun.com/input/XGyzWVyDdEFKDE42W99r?private_key=KEYVALUE&test_value=1"
Here is the code I'm trying to work with unsuccessfully after reading some simple tutorials:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
@IBAction func ColorTwoTapped(_ sender: Any) {
print("Color 2")
}
@IBAction func ColorOneTapped(_ sender: Any) {
print("Color 1")
let scriptUrl = "http://data.sparkfun.com/input/XGyzWVyDdEFKDE42W99r"
let urlWithParams = scriptUrl + "?private_key=KEYVALUE&test_value=1"
let myUrl = NSURL(string: urlWithParams);
let task = URLSession.sharedSession().dataTaskWithURL(myUrl!) {(data, response, error) in
print(String(data: data!, encoding: NSUTF8StringEncoding))
}
task.resume()
}
@IBAction func ColorThreeTapped(_ sender: Any) {
print("Color 3")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
The error I get is
Cannot call value of non-function type 'URLSession'.
Thanks for any advice