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

后端 未结 5 1838
遇见更好的自我
遇见更好的自我 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:31

    One alternative is to just use casting:

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

    It might be the best solution with the current state of the tools, especially if you have code where you're using XCTAssertEqual a lot and don't want to switch to XCTAssertTrue.

    (I noticed @RobNapier made this suggestion in a comment.)

提交回复
热议问题