首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RKObjectManager映射结果问题

RKObjectManager映射结果问题
EN

Stack Overflow用户
提问于 2013-11-10 19:09:52
回答 1查看 398关注 0票数 0

我试图将来自[[RKObjectManager sharedManager] getObjectsAtPath:@"/groups" ...的结果存储在数组中,并想知道为什么数组没有将我的对象存储在getObjectsAtPath之外。

代码语言:javascript
复制
@property (strong, nonatomic) NSArray *groups;

- (void)loadGroups
{

[[RKObjectManager sharedManager]  getObjectsAtPath:@"/groups"  parameters:nil     
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
    [self.refreshControl endRefreshing];

    self.groups = mappingResult.array;
    NSLog(@"GROUP COUNT INSIDE %@", [NSString stringWithFormat:@"%d", _groups.count]);
    NSLog(@"GROUP NAME INSIDE %@",[self.groups objectAtIndex:0]);
    NSLog(@"GROUP NAME INSIDE %@",[[self.groups objectAtIndex:0] valueForKey:@"groupName"]);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
    [self.refreshControl endRefreshing];
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"An Error Has Occurred" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];
}];

NSLog(@"GROUP NAME OUTSIDE %@",[self.groups objectAtIndex:0]);
NSLog(@"GROUP NAME OUTSIDE %@",[[self.groups objectAtIndex:0] valueForKey:@"groupName"]);
NSLog(@"GROUP COUNT OUTSIDE %@", [NSString stringWithFormat:@"%d", self.groups.count]);
}

NSLOG产出:

代码语言:javascript
复制
2013-11-10 12:04:33.281 Test[64618:11603] GROUP NAME OUTSIDE (null)
2013-11-10 12:04:33.294 Test[64618:11603] GROUP NAME OUTSIDE (null)
2013-11-10 12:04:33.345 Test[64618:11603] GROUP COUNT OUTSIDE 0
2013-11-10 12:04:33.482 Test[64618:11603] GROUP COUNT INSIDE 1
2013-11-10 12:04:33.483 Test[64618:11603] GROUP NAME INSIDE <NSManagedObject: 0x957b990> (entity: Group; id: 0x7693570 <x-coredata://174C4545-59FF-4A3A-A3B5-29520354ADD9/Group/p1> ; data: {
    groupDescription = "Admin Group";
    groupId = 1;
    groupName = Admin;
})
2013-11-10 12:04:33.484 Test[64618:11603] GROUP NAME INSIDE Admin
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-10 20:44:51

当你说“getObjectsAtPath之外”时,你指的是成功块之外。原因很简单,因为成功块还没有运行,所以您的属性还没有设置值。这是因为对getObjectsAtPath的调用是异步的,可能需要几十秒才能获得所请求的数据。在成功块被调用之前,您不应该期望数据是可用的。(调用getObjectsAtPath在线程完成之前不会阻塞它)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19893894

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档