34

I am trying to create unit tests using the new XCTest framework introduced in Xcode 5. I have a line in one of my test cases that looks like this:

XCTAssertEqual([self.client stringEncoding], NSUTF8StringEncoding, …);

When I try to run my tests, Xcode spits out this error: "Reference to NSUTF8StringEncoding is ambiguous." I can get the test to work by changing the above line to this:

XCTAssertEqual([self.client stringEncoding], (NSStringEncoding) 4, …);

(This works because 4 is the value of NSUTF8StringEncoding.) This also happens when I assign NSUTF8StringEncoding to a local variable and use it in the XCTAssertEqual() call instead. Why am I getting this error?

bneely
  • 9,083
  • 4
  • 38
  • 46
wjk
  • 1,219
  • 11
  • 27
  • That code works for me. If you put NSUTF8StringEncoding back in the function, and command-click on it, what do you see? – bneely Sep 22 '13 at 00:51
  • @bneely: When I Command-click on the NSUTF8StringEncoding, I am taken directly to its declaration at `NSString.h` line 40. It still doesn’t compile. – wjk Sep 23 '13 at 18:49
  • Which frameworks are you linking with in your unit test target? Which header(s) are you including in the unit test implementation file (the .m file)? – bneely Sep 23 '13 at 23:05
  • I’m #including `` and `` (the latter is the framework that I’m testing). I am linking against the Cocoa, AFNetworking, and XCTest frameworks. Still won’t work. – wjk Sep 24 '13 at 20:56
  • When you search your project for NSUTF8StringEncoding via the Find Navigator, what do you see? – bneely Sep 24 '13 at 21:04
  • Have you tried (NSStringEncoding)NSUTF8StringEncoding in your test? – bneely Sep 24 '13 at 21:06
  • @bneely: I see only references to the symbol in comments, framework code, and once in the unit test that is giving me trouble. Casting the value to type `NSStringEncoding` makes no difference. – wjk Sep 26 '13 at 19:07
  • I'm stumped here. This may be an Apple bug. If you're determined to work around this, you could try changing the test to `XCTAssertTrue(NSUTF8StringEncoding == [self.client stringEncoding], @"");` – bneely Sep 26 '13 at 20:00
  • I get this as well, but it goes away when I actually compile and run the tests so its more of an annoyance. – Aron Jan 22 '14 at 06:00
  • http://stackoverflow.com/questions/19178109/xctassertequal-error-3-is-not-equal-to-3 ? – Larme Feb 18 '14 at 19:11
  • I have also started to get this with one of my build targets after I tweaked the minimum deployment target and SDK version to match between it and the target whose product acts as the bundle loader for the test suite. Stuck :-( – mz2 Jun 24 '14 at 15:37

1 Answers1

0

Please import below framework in your file.

#import <UIKit/UIKit.h>
JayPathak
  • 21
  • 2