[ANN] Camlkit -- macOS/iOS/GNUstep toolkit for OCaml

I’ve encountered this issue before with other protocols, eg NSApplicationDelegate. This SO question discusses why this happens.

You can simply ignore the protocol conformance declaration when you define your CBCentralManager delegate. The protocol conformance is only checked by the Objective-C compiler, not in the runtime. Here’s an example where I’ve not declared the protocol conformance for UIApplicationDelegate and the code just works.

I used to link a stub like this, which will cause the protocol to be loaded in the runtime:

#import <UIKit/UIKit.h>

// UIApplicationDelegate protocol must be referenced in ObjC code
// in order to be loaded in the Objective-C runtime.
@interface _Dummy : NSObject <UIApplicationDelegate>
@end

@implementation _Dummy
@end

You can do something similar for CBCentralManagerDelegate, but it’s not really necessary.

You can open a new topic here for your project related questions, or continue asking in this topic. I don’t mind it either way.

Actually, CBCentralManagerDelegate is not one of these problematic protocols. If you add (flags :standard -ccopt "-framework CoreBluetooth") to your dune file, your example prints “Protocol exists”.

I actually thought this might be something I’d need to do while walking around away from my computer, and then forgot to try it!

So since this check can be done at runtime, I assume that it’s possible that the class whose delegate it is would check it.

(I’m working through this sooo sloooowly. My next thing is run loops :smiley: - I last used Objective-C in the year 2012)

You can also consider a pure-OCaml approach to the problem you are trying to solve. Maybe you can avoid dealing with NSRunLoop/CFRunLoop. Modules Thread and Unix could provide a simpler solution.