We have the (usual?) problem that we need a method that returns a BOOL and can throw an error, inside a Framework that can be used from Objective-C and from Swift. Is there a nice and for the user understandable way to do that?
More detail:
If I just needed a method that returns a BOOL, that would look like this:
- (BOOL)isDoneNow (as you, who will hopefully answer this question, will know) if this should return an error at the same time, I can't do it like this, as in:
- (BOOL)isDone:(NSError**)errorthe return value tells the user if there was an error, but doesn't return any value.
So the usual ways I have found so far to do this are these:
Send the return value as a pointer and fill it:
-(BOOL)getIsDone:(BOOL*)isDone error:(NSError**)erroror: Return an NSNumber that is nil if there is an error or contains a BOOL if not.
-(NSNumber*)isDone:(NSError**)errorIn Objective-C, we so far used the first solution for this. But now the framework needs to nicely map to a swift funtion. Now in Swift, the first solution would map to:
func getIsDone(isDone: UnsafeMutablePointer<ObjCBool>) throwsand the second one to:
func isDone() throws -> NSNumberwhich is really unclear for the user why this is an NSNumber and he has to use .boolValue to actually use it...
As you can see, both variants are really bad. What I would prefer is something like:
func isDone() throws -> Boolor maybe
func getIsDone(isDone: inout Bool) throwsIs there a way to tell the clang compiler to convert it to something like this? Pleeease?
Thanks!