I have this code in ObjC/C:
AVCaptureFocusMode GetFocusModeWithString(NSString *mode) {
if ([mode isEqualToString:@"locked"]) {
return AVCaptureFocusModeLocked;
} else if ([mode isEqualToString:@"auto"]) {
return AVCaptureFocusModeAutoFocus;
} else {
@throw [NSError errorWithDomain: @"FocusError", code: 12];
}
}
It used to be working fine when calling from ObjC code. Now I am rewriting the caller side using swift. However, in swift, this code does not actually throw:
// does not work, swift thinks this function does not throw.
do {
try GetFocusModeWithString(@"auto")
}
Am I doing anything wrong here? Is the ObjC code bad? how can I improve the ObjC code to work nicely with swift?