ios - 我在 iOS 上有一个 Objective-C 应用程序,如何构建 Swift Watch 扩展?

标签 ios objective-c swift apple-watch

我正在更新旧的 Objective-C 应用程序,以包含用 Swift 编写的 Watch 扩展。

我确定要更改嵌入内容包含 Swift 代码默认值: enter image description here

我有以下头文件:

#import <Foundation/Foundation.h>

@interface Elements : NSObject
// designated initializer
-(instancetype)initWithElement:(NSString *)atom
                     AndNumber:(NSNumber *)number;
+(NSDictionary *) elementInfo;
+(NSArray *) atomArray;
@property (strong, nonatomic) NSNumber *mass;
@property (strong, nonatomic) NSString *name;
@property (strong, nonatomic) NSString *ChemicalName;
@end

如何在我的 Swift Watch 扩展中使用上述 Elements 对象?

现在我遇到以下错误:

enter image description here

最佳答案

您需要有一个桥头文件(当您第一次尝试将 obj-c 与 swift 混合时,Xcode 会要求您创建它)。如果您没有让 Xcode 为您创建它,您将必须自己创建它,然后转到所有目标的build设置并在 swift 编译器 -> 代码生成 -> 添加到“Objective-C Bridging Header”下设置:桥接-头文件名.h。 header 准备就绪后,导入您需要在 Swift 中访问的所有 Obj-C header 。

关于ios - 我在 iOS 上有一个 Objective-C 应用程序,如何构建 Swift Watch 扩展?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29572731/

相关文章:

ios - 如何保存在UITableView中滚动时消失的选中标记?

ios - iPad 无法正确缩放 iPhone 应用程序

iphone - 记住swift中2个ViewController的高分

ios - 一个带有 6 个选项卡的 TabBar,一个 ViewController,一个 WebView

ios - 解码 base64String 值返回 nil

ios - 从prepareForSegue访问 TableView IndexPath

objective-c - 特殊字符不适用于自定义字体

ios - 如何从 didSelectRowAtIndexPath 上的 UITableView 中获取 textview 的值?

swift - 从自定义 imageView 类执行 segue?

swift - 在不创建新常量的情况下将可选值解包到保护条件中的预定义变量