Reputation: 427
I modified a function in objective C to throw errors. I then want to catch these errors in Swift. I implemented the Bridging function, and it looks that everything is in order. I am getting the error:
Consecutive statements on a line must be separated by ';'
just right after the command:
try rfduino.send(data)
If I don't use try
, it starts asking me for a second parameter. The function worked before I implemented this error handling. I am using XCode 6.4.
I also read in http://blog.benjamin-encz.de/swift-error-handling-and-objective-c-interop-in-depth/ that XCode only translate the function to a Swift-like error throwing function when the function returns a BOOL or an ObjectiveC type. I also tried that.
What can it be?
My .h file looks like:
- (BOOL)send:(NSData *)data
error:(NSError**) errorPtr;
in .m file:
- (BOOL)send:(NSData *)data
error:(NSError**)errorPtr
{
if (! loadedService) {
if (errorPtr) {
*errorPtr = [NSError errorWithDomain:NSCocoaErrorDomain
code:NSFileNoSuchFileError
userInfo:@{NSLocalizedDescriptionKey: NSLocalizedString(@"No Device Connected.", nil),
NSLocalizedFailureReasonErrorKey: NSLocalizedString(@"The connection is not loaded.", nil),
NSLocalizedRecoverySuggestionErrorKey: NSLocalizedString(@"Try disconnecting and connecting again", nil)
}];
} else {
@throw [NSException exceptionWithName:@"sendDataNoDevice" reason:@"please wait for ready callback" userInfo:nil];
}
return(NO);
}
if ([data length] > max_data) {
if (errorPtr) {
*errorPtr = [NSError errorWithDomain:NSCocoaErrorDomain
code:NSFileNoSuchFileError
userInfo:@{NSLocalizedDescriptionKey: NSLocalizedString(@"No Device Connected.", nil),
NSLocalizedFailureReasonErrorKey: NSLocalizedString(@"The connection is not loaded.", nil),
NSLocalizedRecoverySuggestionErrorKey: NSLocalizedString(@"Try disconnecting and connecting again", nil)
}];
} else {
@throw [NSException exceptionWithName:@"sendDataTooLarge" reason:@"max data size exceeded" userInfo:nil];
}
return(NO);
}
[peripheral writeValue:data forCharacteristic:send_characteristic type:CBCharacteristicWriteWithoutResponse];
return(YES);
}
thanks!
Upvotes: 0
Views: 305
Reputation: 70098
You have to update Xcode.
Consecutive statements...
usually appears when Xcode doesn't understand the syntax: indeed do try catch
is only available in Xcode 7+ with Swift 2.
Upvotes: 1