user4992124 user4992124 - 4 months ago 23
Objective-C Question

How to assert that a function returns an array

I'm writing iOS unit tests for the first time and I'm having some trouble. When I write unit tests in PHP, I can also assert that the returned value of a function is - let's say - an array.

The code below worked, but that might not be the best way to do this, since the content of the array might change.

NSArray *first = [Example getArray];
NSArray *second = @[@"test", @"test2"];

XCTAssertEqualObjects(first, second, @"Example:getArray doesn't return an array.");


What's the proper way to do this in Objective-C?

Answer

Simply put:

XTCAssert([first isKindOfClass:[NSArray class]], @"First isn't an array");