[英]ios - 'autorelease is unavailable' errors and 'ARC forbids explicit message send of autorelease' errors
[英]ARC forbids explicit message send of 'retain'
我正在嘗試使用適用於iOS的Amazon API,該API處理Objective-C中的Amazon網站登錄。 我正在使用此來源 。 但是,當我實現AMZNAuthorizeUserDelegate
,出現以下錯誤消息:
ARC禁止發送“保留”的明確消息。
我以前從未使用過Objective-C,因此如果有人可以幫助我編寫代碼,我將不勝感激。
這是我的代碼:
#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
錯誤消息是正確的: retain
呼叫不再有效。
2011年,使用iOS 5和Mac OS X 10.7在Objective-C語言中添加了自動引用計數 (ARC)。 在ARC之前,您必須通過調用-retain
, -release
和-autorelease
等方法來手動管理應用程序的內存使用情況。 ARC在編譯時自動管理這些調用,因此不允許您自己調用它們。
正如@ Paulw11在他的評論中提到的那樣,您應該可以將其替換為
parentViewController = aViewController
ARC會自動執行正確的操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.