title: RestKit loadObjectsAtResourcePath:delegate works once, but then never again
body: <p>I'm fairly new to Objective-C and XCode, but even newer to RestKit, though been programming in Java for 12 years.</p>
  
  <p>I have an IOS app connected to RestKit and an action to load from a rest server works only the first time, if I go back in the navigation controller and try the same operation again, the <code>loadObjectsAtResourcePath:delegate</code> method is called, but none of the delegate methods ever get called (and I implemented all of them just to log when they happen).</p>
  
  <p>I feel I have missed something fundamental with Restkit, and perhaps the async nature of it, because the mapping is clearly working fine the first time, so the subsequent call must be getting lost in an async queue.</p>
  
  <p>I have googled this, and seen similar people getting stuck with something similar, but tried them all and doesn't seem to make a difference.  Caching is disabled, the <code>objectLoaderDidLoadUnexpectedResponse</code> and <code>didFailWithError</code> never get called, it's getting dropped to the floor.</p>
  
  <p>Code Source:</p>
  
  <p>My XCode project is up on github <a href="https://github.com/tallpsmith/ElasticSearchIOSHead" rel="noreferrer">here</a></p>
  
  <p>The specific View Controller doing the load call is <a href="https://github.com/tallpsmith/ElasticSearchIOSHead/blob/master/ElasticSearchHeadIOS/ESRKServerViewController.m" rel="noreferrer">here</a> (see setUpRestKit method)</p>
  
  <p>The sequence of calls goes like this:</p>
  
  <ul>
  <li>User fills in hostname, and port, and clicks connect</li>
  <li><a href="https://github.com/tallpsmith/ElasticSearchIOSHead/blob/master/ElasticSearchHeadIOS/ESRKConnectionViewController.m" rel="noreferrer">ESRKConnectionViewController.m</a> gets the call via <strong>prepareForSegue</strong> and sets up the shared RKClient with this address (though I find out later the RKClient isn't used much, the RKOBjectManager seems to take just a baseURL, so a bit redundant there)</li>
  <li><strong>ESRKServerViewController.m</strong> then sets the mapping on the RKObjectManager and invokes the <strong>loadObjectsAtResourcePath</strong> passing itself as a delegate (yes I realise probably these mappings should be configured at the start in the App Delegate, but I can't see how setting this up again is anything more than just redundant code)</li>
  <li>the <strong>objectLoader:didLoadObjects</strong> callback is then in charge of taking the mapped object and configuring the model for the table view - this is fired only once.</li>
  </ul>
  
  <p>Enabling the logs, this is the pattern I see, with annotations on when the first call completes, and when the second one starts etc (timestamps trimmed for clarity here):</p>
  
  <pre><code>ElasticSearchHeadIOS[25064:fb03] I restkit:RKLog.m:32 RestKit initialized...
  ElasticSearchHeadIOS[25064:fb03] I restkit.support:RKCache.m:178 Invalidating cache at path: /Users/paulsmith/Library/Application Support/iPhone Simulator/5.1/Applications/BDB8B59F-8307-4F18-A4E7-C55849618D77/Library/Caches/RKClientRequestCache-localhost/SessionStore
  ElasticSearchHeadIOS[25064:fb03] I restkit.network.reachability:RKReachabilityObserver.m:155 Reachability observer initialized with hostname localhost
  ElasticSearchHeadIOS[25064:fb03] D restkit.network:RKClient.m:271 Reachability observer changed for client &lt;RKClient: 0x80756e0&gt;, suspending queue &lt;RKRequestQueue: 0x8082600 name=(null) suspended=YES requestCount=0 loadingCount=0/5&gt; until reachability to host 'localhost' can be determined
  ElasticSearchHeadIOS[25064:fb03] Connecting to http://localhost:9200/ -- http://localhost:9200/ -- http://localhost:9200/
  ElasticSearchHeadIOS[25064:fb03] I restkit.support:RKCache.m:178 Invalidating cache at path: /Users/paulsmith/Library/Application Support/iPhone Simulator/5.1/Applications/BDB8B59F-8307-4F18-A4E7-C55849618D77/Library/Caches/RKClientRequestCache-localhost/SessionStore
  ElasticSearchHeadIOS[25064:fb03] I restkit.network.reachability:RKReachabilityObserver.m:155 Reachability observer initialized with hostname localhost
  ElasticSearchHeadIOS[25064:fb03] D restkit.network:RKClient.m:271 Reachability observer changed for client &lt;RKClient: 0x8087840&gt;, suspending queue &lt;RKRequestQueue: 0x8087a40 name=(null) suspended=YES requestCount=0 loadingCount=0/5&gt; until reachability to host 'localhost' can be determined
  ElasticSearchHeadIOS[25064:fb03] I restkit.network.reachability:RKReachabilityObserver.m:369 Network availability has been determined for reachability observer &lt;RKReachabilityObserver: 0x8088980 host=localhost isReachabilityDetermined=YES isMonitoringLocalWiFi=1039984 reachabilityFlags=-R -----ld&gt;
  ElasticSearchHeadIOS[25064:fb03] D restkit.network:RKClient.m:401 Reachability to host 'localhost' determined for client &lt;RKClient: 0x8087840&gt;, unsuspending queue &lt;RKRequestQueue: 0x8087a40 name=(null) suspended=YES requestCount=1 loadingCount=0/5&gt;
  ElasticSearchHeadIOS[25064:fb03] D restkit.network:RKRequest.m:435 Sending asynchronous GET request to URL http://localhost:9200/_cluster/state.
  ElasticSearchHeadIOS[25064:fb03] T restkit.network:RKRequest.m:381 Prepared GET URLRequest '&lt;NSMutableURLRequest http://localhost:9200/_cluster/state&gt;'. HTTP Headers: {
      Accept = "application/json";
      "Content-Length" = 0;
  }. HTTP Body: .
  ElasticSearchHeadIOS[25064:fb03] I restkit.network.reachability:RKReachabilityObserver.m:369 Network availability has been determined for reachability observer &lt;RKReachabilityObserver: 0x6c5c530 host=localhost isReachabilityDetermined=YES isMonitoringLocalWiFi=1039984 reachabilityFlags=-R -----ld&gt;
  ElasticSearchHeadIOS[25064:fb03] D restkit.network:RKClient.m:401 Reachability to host 'localhost' determined for client &lt;RKClient: 0x80756e0&gt;, unsuspending queue &lt;RKRequestQueue: 0x8082600 name=(null) suspended=YES requestCount=0 loadingCount=0/5&gt;
  ElasticSearchHeadIOS[25064:fb03] D restkit.network:RKResponse.m:195 NSHTTPURLResponse Status Code: 200
  ElasticSearchHeadIOS[25064:fb03] D restkit.network:RKResponse.m:196 Headers: {
      "Content-Length" = 4462;
      "Content-Type" = "application/json; charset=UTF-8";
  }
   ElasticSearchHeadIOS[25064:fb03] T restkit.network:RKResponse.m:203 Read response body: {"cluster_name":"paul","master_node":"FGewvE3-TEKjXugOGJpWmQ","blocks":{},"nodes":{"FGewvE3-TEKjXugOGJpWmQ":{"name":"Namor the Sub-Mariner","transport_address":"inet[/192.168.0.12:9300]","attributes":{}}},"metadata":{"templates":{},"indices":{"melpaul":{"state":"open","settings":{"index.number_of_replicas":"1","index.number_of_shards":"5","index.version.created":"190299"},"mappings":{"project":{"properties":{"projectAddress":{"type":"string"},"id":{"type":"string"},"suburb":{"type":"string"},"name":{"type":"string"},"state":{"type":"string"},"postalAddress":{"type":"string"},"ownerOrganizationID":{"type":"long"},"shortName":{"type":"string"},"deliveryAddress":{"type":"string"},"country":{"type":"string"}}},"organization":{"properties":{"id":{"type":"string"},"tradingName":{"type":"string"},"name":{"type":"string"},"extParticipant":{"type":"string"},"code":{"type":"string"}}},"task":{"properties":{"aggregateCount":{"type":"long"},"dueDateIso":{"type":"string"},"assignedByUser":{"type":"string"},"pertinent":{"type":"boolean"},"assignedByUserId":{"type":"long"},"assignedBy":{"type":"string"},"projectId":{"type":"long"},"type":{"type":"string"},"id":{"type":"string"},"creationDate":{"type":"long"},"assignedToUserId":{"type":"long"},"description":{"type":"string"},"featureId":{"type":"string"},"aggregated":{"type":"boolean"},"assignedToUser":{"type":"string"},"projectName":{"type":"string"},"dueDate":{"type":"long"},"referenceLabel":{"type":"string"}}},"user":{"properties":{"sortlastName":{"type":"string"},"position":{"type":"string"},"lastName":{"type":"string"},"phone":{"type":"string"},"accessEnabled":{"type":"string"},"orgName":{"type":"string"},"directoryVisibility":{"type":"string"},"id":{"type":"string"},"orgId":{"type":"string"},"orgTradingName":{"type":"string"},"title":{"type":"string"},"divisionName":{"type":"string"},"email":{"type":"string"},"sortfirstName":{"type":"string"},"userName":{"type":"string"},"extParticipant":{"type":"string"},"firstName":{"type":"string"},"accountUnlocked":{"type":"string"},"mobile":{"type":"string"}}}},"aliases":[]}}},"routing_table":{"indices":{"melpaul":{"shards":{"0":[{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":0,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":0,"index":"melpaul"}],"1":[{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":1,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":1,"index":"melpaul"}],"2":[{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":2,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":2,"index":"melpaul"}],"3":[{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":3,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":3,"index":"melpaul"}],"4":[{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":4,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":4,"index":"melpaul"}]}}}},"routing_nodes":{"unassigned":[{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":0,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":1,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":2,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":3,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":4,"index":"melpaul"}],"nodes":{"FGewvE3-TEKjXugOGJpWmQ":[{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":0,"index":"melpaul"},{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":1,"index":"melpaul"},{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":2,"index":"melpaul"},{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":3,"index":"melpaul"},{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":4,"index":"melpaul"}]}},"allocations":[]}
   ElasticSearchHeadIOS[25064:1400b] D restkit.network:RKObjectLoader.m:262 Beginning object mapping activities within GCD queue labeled: org.restkit.ObjectMapping
   ElasticSearchHeadIOS[25064:1400b] D restkit.network:RKObjectLoader.m:250 No object mapping provider, using mapping provider from parent object manager to perform KVC mapping
   ElasticSearchHeadIOS[25064:1400b] T restkit.network:RKObjectLoader.m:187 bodyAsString: {"cluster_name":"paul","master_node":"FGewvE3-TEKjXugOGJpWmQ","blocks":{},"nodes":{"FGewvE3-TEKjXugOGJpWmQ":{"name":"Namor the Sub-Mariner","transport_address":"inet[/192.168.0.12:9300]","attributes":{}}},"metadata":{"templates":{},"indices":{"melpaul":{"state":"open","settings":{"index.number_of_replicas":"1","index.number_of_shards":"5","index.version.created":"190299"},"mappings":{"project":{"properties":{"projectAddress":{"type":"string"},"id":{"type":"string"},"suburb":{"type":"string"},"name":{"type":"string"},"state":{"type":"string"},"postalAddress":{"type":"string"},"ownerOrganizationID":{"type":"long"},"shortName":{"type":"string"},"deliveryAddress":{"type":"string"},"country":{"type":"string"}}},"organization":{"properties":{"id":{"type":"string"},"tradingName":{"type":"string"},"name":{"type":"string"},"extParticipant":{"type":"string"},"code":{"type":"string"}}},"task":{"properties":{"aggregateCount":{"type":"long"},"dueDateIso":{"type":"string"},"assignedByUser":{"type":"string"},"pertinent":{"type":"boolean"},"assignedByUserId":{"type":"long"},"assignedBy":{"type":"string"},"projectId":{"type":"long"},"type":{"type":"string"},"id":{"type":"string"},"creationDate":{"type":"long"},"assignedToUserId":{"type":"long"},"description":{"type":"string"},"featureId":{"type":"string"},"aggregated":{"type":"boolean"},"assignedToUser":{"type":"string"},"projectName":{"type":"string"},"dueDate":{"type":"long"},"referenceLabel":{"type":"string"}}},"user":{"properties":{"sortlastName":{"type":"string"},"position":{"type":"string"},"lastName":{"type":"string"},"phone":{"type":"string"},"accessEnabled":{"type":"string"},"orgName":{"type":"string"},"directoryVisibility":{"type":"string"},"id":{"type":"string"},"orgId":{"type":"string"},"orgTradingName":{"type":"string"},"title":{"type":"string"},"divisionName":{"type":"string"},"email":{"type":"string"},"sortfirstName":{"type":"string"},"userName":{"type":"string"},"extParticipant":{"type":"string"},"firstName":{"type":"string"},"accountUnlocked":{"type":"string"},"mobile":{"type":"string"}}}},"aliases":[]}}},"routing_table":{"indices":{"melpaul":{"shards":{"0":[{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":0,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":0,"index":"melpaul"}],"1":[{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":1,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":1,"index":"melpaul"}],"2":[{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":2,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":2,"index":"melpaul"}],"3":[{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":3,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":3,"index":"melpaul"}],"4":[{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":4,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":4,"index":"melpaul"}]}}}},"routing_nodes":{"unassigned":[{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":0,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":1,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":2,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":3,"index":"melpaul"},{"state":"UNASSIGNED","primary":false,"node":null,"relocating_node":null,"shard":4,"index":"melpaul"}],"nodes":{"FGewvE3-TEKjXugOGJpWmQ":[{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":0,"index":"melpaul"},{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":1,"index":"melpaul"},{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":2,"index":"melpaul"},{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":3,"index":"melpaul"},{"state":"STARTED","primary":true,"node":"FGewvE3-TEKjXugOGJpWmQ","relocating_node":null,"shard":4,"index":"melpaul"}]}},"allocations":[]}
   ElasticSearchHeadIOS[25064:1400b]  willMapData
   ElasticSearchHeadIOS[25064:fb03] did finish loading
  </code></pre>
  
  <hr>
  
  <p>Ok the table view showing the mapped data that has come back from the above calls is now done, and I can see the results correctly on screen.  </p>
  
  <h2>I click back on the Navigation controller, try the same request again, and here's what the logs do.  The logs here start just after I click the connect button and start the same calls as above (no other logs occur between the above block and this one below).</h2>
  
  <pre><code>I restkit.support:RKCache.m:178 Invalidating cache at path: /Users/paulsmith/Library/Application Support/iPhone Simulator/5.1/Applications/BDB8B59F-8307-4F18-A4E7-C55849618D77/Library/Caches/RKClientRequestCache-localhost/SessionStore
  I restkit.network.reachability:RKReachabilityObserver.m:155 Reachability observer initialized with hostname localhost
  D restkit.network:RKClient.m:271 Reachability observer changed for client &lt;RKClient: 0x808ce90&gt;, suspending queue &lt;RKRequestQueue: 0x80834c0 name=(null) suspended=YES requestCount=0 loadingCount=0/5&gt; until reachability to host 'localhost' can be determined
  D restkit.network:RKClient.m:256 Reachability observer changed for RKClient &lt;RKClient: 0x80756e0&gt;, disposing of previous instance: &lt;RKReachabilityObserver: 0x6c5c530 host=localhost isReachabilityDetermined=YES isMonitoringLocalWiFi=1039984 reachabilityFlags=-R -----ld&gt;
  Connecting to http://localhost:9200/ -- http://localhost:9200/ -- http://localhost:9200/
  I restkit.support:RKCache.m:178 Invalidating cache at path: /Users/paulsmith/Library/Application Support/iPhone Simulator/5.1/Applications/BDB8B59F-8307-4F18-A4E7-C55849618D77/Library/Caches/RKClientRequestCache-localhost/SessionStore
  I restkit.network.reachability:RKReachabilityObserver.m:155 Reachability observer initialized with hostname localhost
  D restkit.network:RKClient.m:271 Reachability observer changed for client &lt;RKClient: 0x81b0bc0&gt;, suspending queue &lt;RKRequestQueue: 0x81b0d20 name=(null) suspended=YES requestCount=0 loadingCount=0/5&gt; until reachability to host 'localhost' can be determined
  D restkit.network:RKClient.m:256 Reachability observer changed for RKClient &lt;RKClient: 0x81b0bc0&gt;, disposing of previous instance: &lt;RKReachabilityObserver: 0x81b1c80 host=localhost isReachabilityDetermined=NO isMonitoringLocalWiFi=1039984 reachabilityFlags=-- -------&gt;
  I restkit.network.reachability:RKReachabilityObserver.m:369 Network availability has been determined for reachability observer &lt;RKReachabilityObserver: 0x807f2f0 host=localhost isReachabilityDetermined=YES isMonitoringLocalWiFi=1039984 reachabilityFlags=-R -----ld&gt;
  D restkit.network:RKClient.m:401 Reachability to host 'localhost' determined for client &lt;RKClient: 0x808ce90&gt;, unsuspending queue &lt;RKRequestQueue: 0x80834c0 name=(null) suspended=YES requestCount=0 loadingCount=0/5&gt;
  </code></pre>
  
  <p>Here is a <a href="http://people.apache.org/~psmith/restkitObjectLoadingOnce.swf" rel="noreferrer">Jing screencast</a> of what it looks like in the simulator (you can see the break points of the delegate methods getting called the first time around, but then nothing the 2nd)</p>