Hi!
I have a xcode workspace with first objectiveC framework (let’s call it framework#1). This framework has some singletons (+(instancetype)shared
using the dispatch_once idiom.
This code is pretty straight forward and used everywhere :
+ (instancetype)shared { static dispatch_once_t onceToken; static OGAKeyManager *instance = nil; dispatch_once(&onceToken, ^{ instance = [[self alloc] init]; }); return instance; }
I have a second framework (framework#2) in Swift that uses theses singletons (the framework#1 is added as do not embeed
in the framework settings).
And I have an application that uses both frameworks.
If I make a breakpoint inside the dispatch_once alloc/init, I see that I enter 2 times : once when the shared
method is called from framework#1 and another one when it’s called from framework#2.
How is that even possible ? Isn't dispatch_once supposed to handle this ? I asked chatGPT, it points out to some objC/Swift interoperability, but honestly, I don't see what I can do to make it work correctly.
There is no circular dependency (framwork#2 uses framwork#1, but framwork#1 has no clue of framwork#2 existence) Maybe it has something to do with sandbox, but I don't see how can it be.
Does anyone experienced some weird behavior like this ? Thanks