I’ve also been working on an Objective-C wrapper for the Spark API. I’ve taken the approach of creating a SparkCore object (a core) with deviceID and accessToken properties. You can create this object by passing your id and token if you want to hard code it into your app, or you can download those values from the cloud using your user name and password. If you have multiple cores, you can create the object using its name. These methods are,
+(instancetype)coreWithdeviceID:(NSString *) devID accessToken:(NSString *) accessToken;
+(instancetype)coreWithUserName:(NSString *) user password:(NSString *) password;
+(instancetype)coreNamed:(NSString *)coreName userName:(NSString *) user password:(NSString *) password;
+(instancetype)coreWithNewTokenNamed:(NSString *)coreName userName:(NSString *) user password:(NSString *) password;
Once you have the SparkCore object, you can access the Spark.variable() and Spark.function() API with block based methods. There are two different methods to call the Spark.function, one of which allows you to pass an array of keys that are used to create a dictionary of values gotten by parsing the 32 bit int returned by the function. This way, you can combine 2, 3, or 4 values (2 x 16 bit, 1 x 16 bit and 2 x 8 bit, or 4 x 8 bit) in your Spark code and have the method parse it into its components. Those methods are,
-(void) executeFunction:(NSString *)functionName argument:(NSString*) arg completionHandler:(void (^)(NSInteger result, NSError *error))handler
-(void) executeFunction:(NSString *)functionName argument:(NSString*) arg returnKeys:(NSArray *) keys completionHandler:(void (^)(NSDictionary *result, NSError *error))handler
There are four methods for accessing the Spark.variable, corresponding to the four possible return types of INT, DOUBLE, BOOLEAN, and STRING. This is probably overkill, but allows me to return the correct type for each one. These methods are,
-(void) readInt:(NSString *) variable completionHandler:(void (^)(int result, NSError *error))handler;
-(void) readBoolean:(NSString *) variable completionHandler:(void (^)(BOOL result, NSError *error))handler;
-(void) readDouble:(NSString *) variable completionHandler:(void (^)(double result, NSError *error))handler;
-(void) readString:(NSString *) variable completionHandler:(void (^)(NSString *result, NSError *error))handler;
The Xcode project, SparkCoreDemo, is up on GitHub here, https://github.com/edelmar/SparkCoreDemo.git