Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Objective-C bridge is outdated since Xcode 10 / Swift 4 and results in Xcode errors #204

Open
funnel20 opened this issue Sep 3, 2024 · 1 comment

Comments

@funnel20
Copy link
Contributor

funnel20 commented Sep 3, 2024

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 Cosmos

Issue 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:

  1. Add @objc to all of function declarations, e.g.:
@objc public class func setFillMode(_ value: Int, inCosmosView cosmosView: CosmosView) {
  1. Replace @objc in the class declaration of CosmosSettingsObjCBridge by @objcMembers once, 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.

@funnel20 funnel20 changed the title The Objective-C bridge and documentation are outdated since Xcode 10 / Swift 4 The Objective-C bridge is outdated since Xcode 10 / Swift 4 Sep 3, 2024
@funnel20 funnel20 changed the title The Objective-C bridge is outdated since Xcode 10 / Swift 4 The Objective-C bridge is outdated since Xcode 10 / Swift 4 and results in Xcode errors Sep 3, 2024
funnel20 added a commit to funnel20/Cosmos that referenced this issue Sep 3, 2024
1) Resolved "Cannot find type 'XXX' in scope" by adding `import Cosmos`
2) Resolved "No known class method for selector 'YYY'" by replacing `@objc` by `@objcMembers` so all methods within the class will be exposed to Objective-C.
@funnel20
Copy link
Contributor Author

funnel20 commented Sep 3, 2024

@evgenyneu I have prepared a pull request for you: #205

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant