本文介绍了Xcode 8宏NSLocalizedString的模糊扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在单元测试.pch文件中有以下内容,允许我的单元测试找到本地化文件的正确包,这一点工作正常,直到我升级到Xcode8。

I have the following in my unit test .pch file to allow my unit tests to find the right bundle for the localization files and this was working fine until I upgraded to Xcode8.

#undef NSLocalizedString
#define NSLocalizedString(key, comment) [[NSBundle bundleWithIdentifier:@"Tests-Unit"] localizedStringForKey:(key) value:@"" table:nil]

现在,我收到警告

Ambiguous expansion of macro NSLocalizedString 

哪个会解释为什么我的单元测试失败,因为他们找不到本地化的字符串值。

Which would explain why my unit tests fail as they can't find the localized string value anymore.

任何想法有什么问题吗?我现在需要做些什么不同的事情吗?

Any ideas what is wrong there? Is there something I need to now do differently?

编辑:
我觉得这与我的所有事情有关源文件位于 2个目标中,即一个用于项目,一个用于单元测试,这是我们设置它的方式。我正在尝试清理它并从单元测试目标中删除所有源文件并添加

I have a feeling it has something to do with all my source file being in 2 targets i.e one for the project and one for the unit tests which is the way we had it setup. I'm trying to clean this up and removed all my source file from the unit test target and added the

@testable import ProjectName

而不是单元测试文件能够访问我的代码进行测试但我现在得到了

instead to a Unit test file to be able to access my code for testing but i'm now getting

File 'MyFile.swift' is part of module 'ProjectName'; ignoring import.


推荐答案

我最终让它全部恢复运作。

I eventually got it all working again.

让我们假设我们的项目名为 Panda ,它包含Obj-C和Swift文件。所有这些文件都在我们的 Panda PandaTests 目标中。

Let’s pretend our project is called Panda and it consists of both Obj-C and Swift files. All of those files are in both our Panda and PandaTests target.

第1步:确保所有文件都具有正确的目标成员资格,即 Panda 目标:仅源文件,开发框架,图像等和 PandaTests 目标:仅测试文件,测试框架,模拟数据等

STEP 1: Ensure all your files have the right Target Membership i.e. Panda target: Only the source files, development frameworks, images etc and PandaTests target: Only the test files, testing frameworks, mock data etc

第2步:确保您的 Panda 项目具有构建设置 - >启用可测试性设置为是

STEP 2: Ensure your Panda Project has the Build Settings -> Enable Testability set to Yes.

第3步:确保 PandaTests 项目具有构建设置 - >产品模块名称设置为PandaTests

第4步:
通过持有一个很好的清洁按下Option按钮,然后单击Product。你应该看到 Clean Build Folder 选项。

第5步:
对于Swift单元测试,添加 @testable导入Panda 。由于我们现在已经从 PandaTests 目标中删除了所有源代码文件,因此单元测试需要一种访问我们项目文件的方法。这使我们的Swift单元测试能够访问我们的 Panda-Bridging-Header.h 中包含的所有Swift文件和Obj-C文件。

STEP 5:For Swift Unit Tests, add @testable import Panda. Since we have now removed all our source code files from the PandaTests target, the unit tests need a way of accessing our project files. This enables our Swift unit tests to access all our Swift files and those Obj-C files that have been included in our Panda-Bridging-Header.h.

这篇关于Xcode 8宏NSLocalizedString的模糊扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 09:39