Skip to content
rayfix edited this page Jan 12, 2012 · 3 revisions

RestKit uses delegates to signal that mapping operations are complete, an error occurred or some other event has happened. Delegates are normally lot retained. You must be sure that when a delegate is called, it's target is an allocated, valid object. If it is not, your app will crash.

Clients will frequently fetch some objects from the server in a UIViewController like so:

[[RKObjectManager sharedManager] loadObjectsAtResourcePath:path delegate:self];

Behind the scenes, this creates an RKObjectLoader that will send you delegate messages. It might be tempting to get a reference to the RKObjectLoader and retain it, and then when your view controller's destructor is called nil out the loader's delegate. This is certainly possible using the block versions of loadObjectsAtResourcePath. However, a more common idiom is to just issue:

[[RKClient sharedClient].requestQueue cancelRequestsWithDelegate:self];

from the dealloc method of your UIViewController handles the situation nicely. Thanks to Jeff Arena for letting me know about this RestKit patter.

Clone this wiki locally