我正在启动一个目标框架,并希望在其中集成一些快速代码。根据官方文件。 (https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-XID_78)
Because the generated header for a framework target is part of the framework’s public interface, only declarations marked with the public modifier appear in the generated header for a framework target. You can still use Swift methods and properties that are marked with the internal modifier from within the Objective-C part of your framework, as long they are declared within a class that inherits from an Objective-C class.
但是,我发现无法访问 swift 的内部部分,例如:
@objc 内部类A:NSObject {}
最佳答案
引用说“您仍然可以使用用内部修饰符标记的 Swift 方法和属性”(添加了强调)。在您的示例中,它是类(不是方法或属性),它是内部
。如果您将类设为public
并添加一个内部方法,您应该能够访问该方法。
编辑:以下内容对我有用:
swift :
@objc public class MyClass : NSObject {
internal func bar() -> String { return "foobar" }
}
objective-C :
#import "MyApplication-Swift.h"
MyClass *foo = [[MyClass alloc] init];
NSLog(@"%@", [foo bar]);
请注意,必须构建代码才能更新生成的 MyApplication-Swift.h
。
关于ios - 将swiftui集成到objective c框架中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31352395/