-1

I've got my project written in Objective-C. I am learning about bridging.

I bridged successfully Swift into my Objective-C project. I did some VC pushing between Objective-C VC and Swift VC. Everything works as it supposed to.

However, I created the reference to my Objective-C NetworkManager (I used Singleton pattern) in my Swift file like that:

let networkManager = NetworkManager.sharedManager()

For some reason I cannot use methods from it.

networkManager.getUserInfo() // .getUserInfo() will not appear!

Just to show you how I've created my NetworkManager as a Singleton. I found that solution online and it was quite old, if you have any better solution, I would be more than happy to get some insight:

+ (id)sharedManager {
    static NetworkManager *sharedMyManager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedMyManager = [[self alloc] init];
    });
    return sharedMyManager;
}

-(id)init {
    if (self = [super init]) {
        someProperty = @"Default Property Value";
        self.cache = [[NSCache alloc] init];
    }
    return self;
}

Not sure what is the issue here. Thank you all for the help.

Jakub Gawecki
  • 801
  • 2
  • 6
  • 14

1 Answers1

0

For those who may look for the answer in the future.

I've been advised to not use id type when bridging with Swift. I've changed:

+ (id)sharedManager {

to

+ (NetworkManager *)sharedManager

And now everything works fine.

Jakub Gawecki
  • 801
  • 2
  • 6
  • 14
  • 1
    See [Why is instancetype used?](https://stackoverflow.com/questions/36020540/why-is-instancetype-used) – Willeke May 09 '21 at 11:45