Coder Social home page Coder Social logo

Comments (10)

lswith avatar lswith commented on June 4, 2024

you should include the swift-Swift.h as well

from rules_apple.

endpress avatar endpress commented on June 4, 2024

@lswith my swift-Swift.h

#if defined(__has_feature) && __has_feature(modules)
@import ObjectiveC;
@import _oc;
#endif

#pragma clang diagnostic ignored "-Wproperty-attribute-mismatch"
#pragma clang diagnostic ignored "-Wduplicate-method-arg"

SWIFT_CLASS("_TtC5swift10SwiftClass")
@interface SwiftClass : NSObject <OCDelegate>
- (void)hello;
- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
@end

#pragma clang diagnostic pop

from rules_apple.

endpress avatar endpress commented on June 4, 2024

@lswith @dmishe
I think it is a bug. swift library deps oc library. so the generated swift-Swift.h use @import _oc , but oc library cann't use @import syntax

from rules_apple.

dmishe avatar dmishe commented on June 4, 2024

Nice catch. This is a side-effect of incomplete support for objc modules in Bazel. If you remove enable_modules attributes, and import oc headers directly in your objc source, the problem should be resolved.

from rules_apple.

endpress avatar endpress commented on June 4, 2024

@dmishe But my swift library used OCObject, the generated swift-Swift.h still has @import _oc,
how do I change my swift calss ? SwiftClass.swift

import UIKit
import _oc
public class SwiftClass: NSObject, OCDelegate { 
    var oc1: OCObject?
    public func hello() {        
    }
}

If I remove OCDelegate , the swift-Swift.h have no @import _oc,

import UIKit
import _oc
public class SwiftClass: NSObject { 
    var oc1: OCObject?
    public func hello() {        
    }
}

the swift-Swift.h is

#if defined(__has_feature) && __has_feature(modules)
@import ObjectiveC;
#endif

#pragma clang diagnostic ignored "-Wproperty-attribute-mismatch"
#pragma clang diagnostic ignored "-Wduplicate-method-arg"

SWIFT_CLASS("_TtC5swift10SwiftClass")
@interface SwiftClass : NSObject
- (void)hello;
- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
@end

#pragma clang diagnostic pop

from rules_apple.

dmishe avatar dmishe commented on June 4, 2024

You will be able to import objc_library as a module in Swift without enable_modules. We do some special things for swift_library targets that makes this possible.

from rules_apple.

endpress avatar endpress commented on June 4, 2024

If I add OCDelegate, it appears again

import UIKit
import _oc
public class SwiftClass: NSObject, OCDelegate { 
    var oc1: OCObject?
    public func hello() {        
    }
}

the swift-Swift.h

#if defined(__has_feature) && __has_feature(modules)
@import ObjectiveC;
@import _oc;
#endif

#pragma clang diagnostic ignored "-Wproperty-attribute-mismatch"
#pragma clang diagnostic ignored "-Wduplicate-method-arg"

SWIFT_CLASS("_TtC5swift10SwiftClass")
@interface SwiftClass : NSObject <OCDelegate>
- (void)hello;
- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
@end

#pragma clang diagnostic pop

Because OCDelegate is decleared in _oc, so @import _oc is added in swift-Swift.h

from rules_apple.

dmishe avatar dmishe commented on June 4, 2024

Yep and that's fine. The important thing is that without enable_modules=1 on the Objective-C side, those imports will never be hit (since __has_feature(modules) will return false).

The downside, as a mentioned above, is that you will need to import oc headers before the swift header every time you use it.

from rules_apple.

endpress avatar endpress commented on June 4, 2024

@dmishe really really thank you.

from rules_apple.

dmishe avatar dmishe commented on June 4, 2024

No problem.

from rules_apple.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.