XCTAssertEqual error: (“3”) is not equal to (“3”)

后端 未结 5 1829
遇见更好的自我
遇见更好的自我 2020-12-30 19:11
NSMutableArray *arr = [NSMutableArray array];
[arr addObject:@\"1\"];
[arr addObject:@\"2\"];
[arr addObject:@\"3\"];

// This statement is fine.
XCTAssertTrue(arr.c         


        
5条回答
  •  攒了一身酷
    2020-12-30 19:26

    I have had this problem, too. As @ephemera and @napier indicated, this is a type issue.

    It can be solved by supplying a value of the correct type, using the c-literal modifiers.

    XCTAssertEqual(arr.count, 3ul, @"Wrong array size.");
    

    You can find the correct type by looking up the return type of the function used on the left hand side - ALT-click on arr.count:

    - (NSUInteger)count;
    

    Now ALT-click on NSUInteger to find its type:

    typedef unsigned long NSUInteger;
    

    Now find the c literal numeric format for unsigned long - google is a good friend but this page works:

    http://www.tutorialspoint.com/cprogramming/c_constants.htm

    As a quick hint here, you may need to use U (unsigned) L (long) or F (float), and make sure you write 1.0 instead of 1 to get a double. Lowercase also works, as in my example above.

提交回复
热议问题