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

[SR-8330] Obj-C methods returning @objc-marked swift classes are not visible in swift code in frameworks #50858

Closed
kam800 opened this issue Jul 20, 2018 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@kam800
Copy link

kam800 commented Jul 20, 2018

Previous ID SR-8330
Radar None
Original Reporter @kam800
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode 10.0 beta (10L176w)

Xcode 9.4.1 (9F2000)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 0bf9867bbcaabbe05421c979c5b5808c

duplicates:

  • SR-4827 Incorrect result resolving type for Obj-C block

Issue Description:

When some Swift class has @objc name override, and some Obj-C class has method which returns the Swift class instance, then the Obj-C method is not visible in all the Swift code in the same framework (it is visible in the main app, not in framework).

Swift class:

@objc(Swift_Class_ForObjC)
public class Swift_Class: NSObject {}

Obj-C header:

@class Swift_Class_ForObjC;

@interface ObjC_Class : NSObject
- (Swift_Class_ForObjC *)createSwiftClassObject;
@end

Obj-C implementation:

#import "ObjC_Class.h"
#import <SampleFramework/SampleFramework-Swift.h>

@implementation ObjC_Class

- (Swift_Class_ForObjC *)createSwiftClassObject {
    return [[Swift_Class_ForObjC alloc] init];
}

@end

Problematic Swift code:

class ProblemHere {
    let o = ObjC_Class()

    // `ObjC_Class.createSwiftClassObject()` returns `Swift_Class` instance,
    // `Swift_Class` has `@objc(Swift_Class_ForObjC)` – this makes the method
    // invisible for other Swift code.
    func followingLineDoesNotCompile() {
        _ = o.createSwiftClassObject()

    }
}

Results:

/tmp/ObjcSwiftBridgingProblem/SampleFramework/ProblemHere.swift:8:13: error: value of type 'ObjC_Class' has no member 'createSwiftClassObject'
        _ = o.createSwiftClassObject()
            ^ ~~~~~~~~~~~~~~~~~~~~~~

After removing Swift_Class_ForObjC name override (and fixing all references), the code starts to compile.

Sample project: https://github.com/kam800/ObjcSwiftBridgingProblem

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

1 participant