ios - Restkit - NSArray property is always null -


i'm beginner restkit (i have ios experience) , i'm having problems nsarray not being populated rkmappingresult. populates in actual 'block' if call access in viewdidload(), prints out null.

could please advise or provide tips/links articles?

thanks lot!

here code -

-(void) loaddata {      rkobjectmapping *mapping = [rkobjectmapping mappingforclass:[venue class]];     [mapping addattributemappingsfromdictionary:@{      @"name":   @"name", @"location.address" : @"address", @"location.city" : @"city"}];      nsstring *urlstring = [nsstring stringwithformat:@"https://api.foursquare.com/v2/venues/search?ll=55.903324,-3.171383&categoryid=4bf58dd8d48988d18f941735&client_id=%s&client_secret=%s&v=20130717", kclientid, kclientsecret];     nsurl *baseurl = [nsurl urlwithstring:urlstring];      rkresponsedescriptor *responsedescriptor = [rkresponsedescriptor responsedescriptorwithmapping:mapping method:rkrequestmethodany pathpattern:nil keypath:@"response.venues" statuscodes:nil];      nsurlrequest *request = [nsurlrequest requestwithurl:baseurl];      rkobjectrequestoperation *operation = [[rkobjectrequestoperation alloc] initwithrequest:request responsedescriptors:@[responsedescriptor]];      [operation setcompletionblockwithsuccess:^(rkobjectrequestoperation *operation, rkmappingresult *result) {         //set array of venues result of got         //nslog(@"%@", [result array]);          nsarray *venues = [result array];         self.arrayofvenues = venues; //self.arrayofvenues null when call in other methods     } failure:nil];     [operation start]; }   - (void) viewdidappear:(bool)animated {     [super viewdidappear:yes];     nslog(@"%@", self.arrayofvenues);  }  - (void)viewdidload {     [super viewdidload];     //load venue data     self.title = @"venues";     [self loaddata];     nslog(@"%@", self.arrayofvenues); } 

try self.arrayofvenues = [venues copy];

i think might losing reference 'venues' when leave block , variable goes away.

also:

it populates in actual 'block' if call access in viewdidload(), prints out null.

bear in mind, block needs complete before try access array. viewdidload going fire before block finishes, , viewdidappear.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -