m.y m.y - 9 months ago 523
iOS Question

Xcode 8 Ambiguous expansion of macro NSLocalizedString

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]

Now, I get the warning

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?

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.

m.y m.y
Answer Source

I eventually got it all working again. I wrote about the steps here: https://myioscache.wordpress.com/2016/11/03/setting-up-unit-tests-xcode-8/