我有一个具有私有NSArray变量的视图控制器.变量在viewDidLoad方法中初始化.当didReceiveMemoryWarning被称为时,会出现一些问题:
nil?nil必须重新创建的方法?视图控制器是否调用viewDidLoad方法来重新创建它?我问,因为视图的其他方法需要这个变量,如果它是不可行的nil.
谢谢!
我正在尝试将类型id的NSInvocation对象传递给对象.编译器建议我像这样做一个桥接演员:
[invocation setArgument:(__bridge void *)(argument) atIndex:idx];
Run Code Online (Sandbox Code Playgroud)
这样可以,我应该做些什么来防止内存泄漏或其他问题吗?
memory-management casting objective-c automatic-ref-counting
我正在尝试在REST API上通过ID请求运行查找.我正在使用RestKit 0.20.我有一个Location对象.它有一个id属性.我想向'/ locations /:id'发出GET请求,并以JSON的形式接收完整的对象.我有后端,它正在工作.我现在正在尝试编写iOS客户端代码.
这就是我所拥有的:
RKObjectManager* m = [RKObjectManager sharedManager];
RKObjectMapping* lmap = [RKObjectMapping requestMapping];
[lmap addAttributeMappingsFromArray:@[@"id"]];
RKRequestDescriptor* req = [RKRequestDescriptor requestDescriptorWithMapping:lmap objectClass:[Location class] rootKeyPath:nil];
[m addRequestDescriptor:req];
Location* l = [[Location alloc] init];
l.id = [NSNumber numberWithInt:177];
[m getObject:l path:@"locations/:id" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(@"LOADED: %@", [mappingResult firstObject]);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"FAILED");
}];
Run Code Online (Sandbox Code Playgroud)
在运行上面的代码之后,Restkit不会从具有在Location对象中设置的ID属性的路径替换':id:.
你们有什么想法我做错了吗?
更新:
我为Location类设置了请求和响应描述符.我为find_by_id请求添加了一个路由,但它是一个命名路由,而不是一个类路由.当我使用getObject:path:参数:success:failure方法时,路由器没有填写'id'占位符(无论它是否被命名为'id','object_id','identity'或其他什么).
我找到的解决方案是这样的:
我遇到的问题是当使用NamedRoute时:
RKRoute * route = [RKRoute routeWithClass:className pathPattern:path method:RKRequestMethodFromString(method)];
[objectManager.router.routeSet addRoute:route];
Run Code Online (Sandbox Code Playgroud)
然后使用getObject:path:参数:success:failure方法查询对象不会导致路由器填写URL路径中的任何占位符.