I am new to Swift and would like to subscribe to a server side event. The SDK documentation gives example code for Swift and Obj-C, except for the section on server side events which is only in Obj-C. I have tried to rewrite in Swift but my knowledge of Swift is still very new. Could someone help with changing this code to be Swift compatible
// The event handler:
SparkEventHandler handler = ^(SparkEvent *event, NSError *error) {
if (!error)
{
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Got Event %@ with data: %@",event.event,event.data);
});
}
else
{
NSLog(@"Error occured: %@",error.localizedDescription);
}
};
// This line actually subscribes to the event stream:
id eventListenerID = [[SparkCloud sharedInstance] subscribeToAllEventsWithPrefix:@"temp" handler:handler];
Cannot convert value of type ‘SparkEventHandler’ (aka ‘(event: SparkEvent, error: ImplicitlyUnwrappedOptional) -> ()’) to expected argument type ‘SparkEventHandler!’
HI,
This has got me part of the way there, but I am receiving the same error as above on the last line.
Cannot convert value of type ‘SparkEventHandler’ (aka ‘(event: SparkEvent, error: ImplicitlyUnwrappedOptional) -> ()’) to expected argument type ‘SparkEventHandler!’
I am still learning Swift so a little confused by this error, please help
If possible, could you share a bit more of the swift code? I’m about to try this tomorrow and am also learning swift in the process. Could you include how you set up the spark connection in the first place?