I am creating a temp out to test different parts of a project. Currently I need to turn something on and off, very basic to start. My issue is that when using the example code for calling a function I run into a compiler error. Does this have something to do with the callFunction method?? Appreciate your help.
Here is the compiler error:
/Users/dan/Desktop/test8/test8/ViewController.swift:18:57: Cannot call value of non-function type ‘((String, [Any]?, ((NSNumber?, Error?) -> Void)?) -> URLSessionDataTask)!’
import UIKit
class ViewController: UIViewController {
var myPhoton : Any?
@IBAction func onButton(_ sender: Any){
let funcArgs = ["D7",1] as [Any]
var task = (myPhoton! as AnyObject).callFunction("digitalWrite", withArguments: funcArgs) { (resultCode : NSNumber?, error : NSError?) -> Void in
if (error == nil) {
println("LED on D7 successfully turned on")
}
}
var bytesToReceive : Int64 = task.countOfBytesExpectedToReceive
}
@IBAction func loginButton(_ sender: Any) {
SparkCloud.sharedInstance().login(withUser: "************", password: "***********")
print("Logged in")
if SparkCloud.sharedInstance().injectSessionAccessToken("xxxxxxxxxxxx") {
print("Session is active")
} else {
print("Bad access token provided")
}
var myPhoton : SparkDevice?
SparkCloud.sharedInstance().getDevices { (sparkDevices:[Any]?, error:Error?) -> Void in
if let e = error {
print("Check your internet connectivity")
}
else {
if let devices = sparkDevices as? [SparkDevice] {
for device in devices {
print(device)
if device.name == "photon_1" {
myPhoton = device
}
}
}
}
}
}
@IBAction func offButton(_ sender: Any) {
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}