Search code examples
iphoneobjective-cioscocoa-touchrestkit

RestKit not working when used in a static library


I am wanting to write a static library which uses RestKit, for an iOS application -- but the RestKit calls are not working in the static library's unit tests.

I'm almost certain that I'm doing something completely silly here, but I cannot figure out what this is.

Using the static library in an iOS application, and running it in the iOS Simulator, works as desired.

Is there something that needs to be done to get RestKit to work in a static library as opposed to in an iOS application?

I've created a sample Xcode 4 project here.

The code calling my API is simple:

+ (void)testRestKit
{ 
    NSString* URL = @"http://0.0.0.0:3000/api";
    RKClient* client = [RKClient clientWithBaseURL:URL username:@"[email protected]" password:@"password"];
    [client get:@"/users/current" delegate:nil];
}

My test is just:

- (void)testExample
{
    [MyLib testRestKit];
    sleep(10);
}

Note: I added the sleep just in case it was a timing thing, where the unit tests would finish without RestKit being given a chance to complete the API call. It did not help.

Even though the RestKit call does not work, there are no visible errors either.

Update: For those interested in doing something similar, you may also want to check out Daniel Jalkut's RSTestingKit. Essentially they are classes that provide, among a few other things, what the solution provided here does.


Solution

  • Sleeping the thread when you're waiting for something to happen isn't likely to help, but you could try cranking the run loop around a few times:

    - (void)testExample
    {
        [MyLib testRestKit];
        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:25]];
    }
    

    I haven't really looked into this thoroughly enough to be confident it'll help (or to explain why, if it does), but it's worth a try.