Search code examples
iosunit-testingcocoaxctestocmock

OCMock setup for iOS with CocoaPods


Trying to set up OCMock in iOS using CocoaPods, have a problem that persists in a new (trivial) project. This is in Xcode 8 but I suspect the problem is the setup rather than the use of CocoaPods.

I have the error: implicit declaration of function ‘OCMClassMock’ is invalid in C99

In my Podfile I have the following: pod 'OCMock', '~> 2.2'

I then followed the ocmock iOS Project setup as best I could and did the following:

  • added the library to the test target set linker flags
  • added #import to my test .m file
  • Added Header Search Paths as $(PROJECT_DIR)/Pods/OCMock
  • Set always Search User Paths to yes

#import <OCMock/OCMock.h> @interface FinanceCalcWithTestsTests : XCTestCase @end - (void)testMasterViewControllerDeletesItemsFromTableView { id tableViewMock = OCMClassMock([UITableView class]); }


Solution

  • Okay, I just noticed what could be the solution: you are telling CocoaPods to get OCMock 2.2, but you are trying to use a feature that was only introduced in OCMock 3.0...