In my code I have a lazy var:
lazy var myService = {
return JSObjection.defaultInjector().getObject(MyService) as? MyService
}()
In the same file I try to call a function of myService
:
func foo() {
myService?.getSomeStringsFrom(nil)
}
MyService is defined in an Objective-C source file:
@interface MyService : NSObject
- (NSArray *) getSomeStringsFrom:(NSString *)aString;
@end
@implementation MyService
- (NSArray *) getSomeStringsFrom:(NSString *)aString {
return nil;
}
@end
The code cannot be compiled because the call of getSomeStringsFrom(nil)
triggers an error message (twice):
<unknown>:0: error: 'Int' is not convertible to 'ObjCBool'
This does not make sense - I am doing the same with other services and XCode does not complain about it. Is it a compiler bug? I am using XCode 6.4 and Swift 1.2.
EDIT: After more digging in the code I found out that the error message can also be triggered by instantiating MyService
. In the following answer, you will see the real "root" of the problem.
The listed Objective-C file was incomplete. At the beginning, there was one crucial enum definition which broke the compilation process as soon as the file was used from within my Swift code:
Apparently, Swift dislikes
BOOL
when it comes to enums. I do not know why but as soon as I convertBOOL
toBoolean
the error vanishes.