尝试在 Swift 中使用 ObjectiveC 代码时构建失败

Build fail when trying to use ObjectiveC code in Swift

本文关键字:代码 ObjectiveC 构建 失败 Swift      更新时间:2023-10-16

我正在尝试使用来自另一个目标的 Objective-C 类之一,在我的扩展目标内的 Swift 类中。
我创建了<Project-Name>-Bridging-Header.h并包含了那个 objective-c 文件,但由于 "Cryptor.h"<CommonCrypto/CommonDigest.h> 中的构建错误,构建无法编译。我相信这与CommonCrypto框架有关。这是我的Bridging-Header.h的样子:

#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>
#import <GooglePlus/GooglePlus.h>
#import <Security/Security.h>
#import <CommonCrypto/CommonCrypto.h>
#import <CommonCrypto/CommonDigest.h>

我想这是由于通用加密库。有没有人遇到过同样的问题并解决了它?

编辑:具体来说,我收到构建错误 - CommonDigest.h 中的"缺少@end",并且因为 CommonDigest.h 没有获得构建,因此 Cryptor.h 中出现错误。

我不知道它是否能解决您的问题,但桥头有时有点问题。至少对我来说是这样。

尝试编辑标题并像这样导入文件:

#import "FacebookSDK.h"
#import "GooglePlus.h"
#import "Security.h"
#import "CommonCrypto.h"
#import "CommonDigest.h"

我已经删除了 UIKit-header,因为你并不真正需要它,因为 swift 有自己的 UIKit。