[英]ARC forbids explicit message send of 'retain'
I'm trying to use Amazon API for iOS that handles the login for Amazon website in Objective-C. 我正在尝试使用适用于iOS的Amazon API,该API处理Objective-C中的Amazon网站登录。 I'm using this source .
我正在使用此来源 。 However, when I implement
AMZNAuthorizeUserDelegate
, I get the following error message: 但是,当我实现
AMZNAuthorizeUserDelegate
,出现以下错误消息:
ARC forbids explicit message send of 'retain'.
ARC禁止发送“保留”的明确消息。
I've never used Objective-C before so I would appreciate if anyone could help me with the code. 我以前从未使用过Objective-C,因此如果有人可以帮助我编写代码,我将不胜感激。
Here is my code: 这是我的代码:
#import <LoginWithAmazon/LoginWithAmazon.h>
#import "AMZNAuthorizeUserDelegate.h"
#import "AMZNGetProfileDelegate.h"
@implementation AMZNAuthorizeUserDelegate
- (id)initWithParentController:(ViewController*)aViewController {
if(self = [super init]) {
parentViewController = [aViewController retain];
}
return self;
}
- (void)requestDidSucceed:(APIResult *)apiResult {
AMZNGetProfileDelegate* delegate = [[[AMZNGetProfileDelegate alloc] initWithParentController:parentViewController] autorelease];
[AIMobileLib getProfile:delegate];
}
- (void)requestDidFail:(APIError *)errorResponse {
NSString *message = errorResponse.error.message;
// Your code when the authorization fails.
[[[[UIAlertView alloc] initWithTitle:@"" message:[NSString
stringWithFormat:@"User authorization failed with message: %@",
errorResponse.error.message] delegate:nil
cancelButtonTitle:@"OK"otherButtonTitles:nil] autorelease] show];
}
@end
The error message is correct: the call to retain
is no longer valid. 错误消息是正确的:
retain
呼叫不再有效。
Automatic Reference Counting , or ARC, was added to the Objective-C language in 2011 with iOS 5 and Mac OS X 10.7. 2011年,使用iOS 5和Mac OS X 10.7在Objective-C语言中添加了自动引用计数 (ARC)。 Prior to ARC, you had to manage the memory usage of your app manually with calls to methods such as
-retain
, -release
, and -autorelease
. 在ARC之前,您必须通过调用
-retain
, -release
和-autorelease
等方法来手动管理应用程序的内存使用情况。 ARC manages these calls automatically at compile time, and, as such, does not allow you to call them yourself. ARC在编译时自动管理这些调用,因此不允许您自己调用它们。
As @Paulw11 mentions in his comment, you should be able to replace that line with 正如@ Paulw11在他的评论中提到的那样,您应该可以将其替换为
parentViewController = aViewController
and ARC will do the correct thing automatically. ARC会自动执行正确的操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.