ios - 将swiftui集成到objective c框架中

标签 ios swift frameworks

我正在启动一个目标框架,并希望在其中集成一些快速代码。根据官方文件。 (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/

相关文章:

ios - 从 ScrollView 中拖出一个项目

php - 在大型 PHP 框架之一之上编写的论坛/论坛

ASP.NET 权限框架?

iphone - 有没有 API 可以在两个 iphone/ipod Touch/ipad 之间共享数据? (游戏套件除外)

ios - NSDate - 添加天数不会改变年份值

ios - 如何在按下 CollectionViewCell 内的按钮后呈现 ViewController

ios - Swift - 以触觉、流畅的方式为按钮设置动画的最佳方式?向下滑动菜单按钮?

ios - Swift 保留周期

ios - 使用 super View 从 Swift 获取 UITableViewCell 到 Objective-C

ios - 形状,多边形,不会 swift 显示在 GoogleMaps 上