-
Notifications
You must be signed in to change notification settings - Fork 371
Open
Description
Please consider submitting the following information (if relevant):
- Library setup method: CocoaPods
- Version of the library: 23.0.0
- Xcode version: 15.4
- OS version iOS 17.6.1
When embedding the project into my Objective-C project with latest Xcode 15.4 while following the manual, I get a ton of Xcode errors.
I have related them to 2 root causes and provide solutions below:
Issue 1 - Cannot find type 'XXX' in scope
The bridge file errors:
CosmosSettingsObjCBridge.swift:38:72 Cannot find type 'CosmosView' in scope
CosmosSettingsObjCBridge.swift:39:26 Cannot find 'StarFillMode' in scope
CosmosSettingsObjCBridge.swift:50:47 Cannot find type 'CosmosView' in scope
etc.
Solution
Add an import to the top of this file:
import CosmosIssue 2 - No known class method for selector 'YYY'
Wherever I use CosmosSettingsObjCBridge in my ViewControllers, I get errors like:
ViewController.m:53:31 No known class method for selector 'setFillMode:inCosmosView:'
It appears that the functions in the Bridge file are no longer accessible since Xcode 10 / Swift 4.
Solution
This can be resolved in 2 ways:
- Add
@objcto all of function declarations, e.g.:
@objc public class func setFillMode(_ value: Int, inCosmosView cosmosView: CosmosView) {- Replace
@objcin the class declaration ofCosmosSettingsObjCBridgeby@objcMembersonce, so all methods within the class will be exposed to Objective-C:
@objcMembers public class CosmosSettingsObjCBridge: NSObject {According to this article, is available since iOS 8.0.
Option 2 is simple and elegant and resolves all warnings.
Metadata
Metadata
Assignees
Labels
No labels