2

我正在尝试使用 Fastlane 使用快照工具截取我的应用程序的屏幕截图。但是,转换为 Objective-C 似乎无法正常工作。我已将 Project-Swift.h 导入到我的 ProjectUITests.m 文件中,并且包含以下代码:

SnapshotHelper *snapshotHelper = [[SnapshotHelper alloc] init];
[snapshotHelper setLanguage:app];
[snapshotHelper snapshot:@"01Homescreen" waitForLoadingIndicator:YES];

但是,当我在命令行中运行命令“快照”时,出现以下错误:

Testing failed:
Use of undeclared identifier 'SnapshotHelper'
Use of undeclared identifier 'snapshotHelper'

(1 failure)
[12:14:52]: Exit status: 65
[12:14:52]: Tests failed - check out the log above

所以我的问题是,如何让 SnapshotHelper.swift 文件在我的 ProjectUITests.m 文件中成功运行?

4

1 回答 1

2

我不得不更改 SnapshotHelper.swift 文件:

var deviceLanguage = ""

@objc class SnapshotHelper : NSObject { // <--- add this

@available(*, deprecated, message="use setupSnapshot: instead")
class func setLanguage(app: XCUIApplication) {
    setupSnapshot(app)
}

...

} // ...@objc class

(这里是github上的相关问题:https ://github.com/fastlane/snapshot/issues/228 )

有时我的 Xcode 没有为我创建桥接头。最简单的解决方法是从项目中删除 swift 文件并再次添加。通常然后 Xcode 会询问我是否想要桥接头。

最终,您可能需要转到目标的 Build Settings > Apple LLVM 7.0 - Language - Modules > Enabled Modules (C and Objective-C) = YES 。

于 2016-01-05T19:48:42.093 回答