I have an Objective-C app with a new iOS 14 Widget (a Swift target), and I want to use a few methods from an Objective-C class in my Swift target, but am having one issue with it.
The class is called SharedUtils, and the methods are marked as class methods in the .h file. I don't create instances of this class, I just use the methods.
One of the methods I want to use is:
This works fine in the Objective-C main app, i.e.:
In the Swift target, I start typing:
and Xcode autocompletes to:
If I don't set the bridging header in the widget target's build settings, or I remove the import from within the bridging-header.h file, Xcode cannot autocomplete the line, so I know that the Swift target can see the SharedUtils code. All good so far.
However, when trying to build the code, Xcode errors with:
The class is called SharedUtils, and the methods are marked as class methods in the .h file. I don't create instances of this class, I just use the methods.
One of the methods I want to use is:
Code Block objective-c + (NSString *)symbolForCategoryId:(NSNumber *)categoryId;
This works fine in the Objective-C main app, i.e.:
Code Block objective-c [SharedUtils symbolForCategoryId:myId];
In the Swift target, I start typing:
Code Block swift SharedUtils.symbol ...
and Xcode autocompletes to:
Code Block swift SharedUtils.symbol(forCategoryId: NSNumber(value: myId))
If I don't set the bridging header in the widget target's build settings, or I remove the import from within the bridging-header.h file, Xcode cannot autocomplete the line, so I know that the Swift target can see the SharedUtils code. All good so far.
However, when trying to build the code, Xcode errors with:
Any idea how to get this to work? I've used Objective-C code in a Swift app before and not had an issue, but the code was all in the same target, so I'm thinking it's something to do with that?Cannot find type 'SharedUtils' in scope