Bra*_*cil 2 memory-management objective-c ios
我正在学习Objective-C,这是一本名为Objective-C基础知识的书,发表于2011年.它正在构建一个简单的应用程序来介绍iOS概念并教授Objective-C语言.似乎自本书出版以来,平台或语言发生了一些变化.当我尝试从书中构建代码时(以下摘录的关键段落),我收到此错误:
autorelease is unavailable: not available in automatic reference counting mode
ARC forbids explicit message send of 'autorelease'
Run Code Online (Sandbox Code Playgroud)
错误消息出现在上面几行,其中autorelease实际上在代码中使用.
我只有大约1小时的Objective-C和iOS经验,所以我不知道如何解决这个问题,所以我可以继续阅读这本书.任何帮助,将不胜感激.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){ #### error message here
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier]autorelease]; ### autorelease used here
}
cell.textLabel.text = [NSString
stringWithFormat:@"Rental Property %d", indexPath.row];
NSLog(@"Rental Property %d", indexPath.row);
return cell;
}
Run Code Online (Sandbox Code Playgroud)
如果我无法解决这些类型的小问题,那么我将无法跟上这本书.如果我可以使用某种版本系统(比如rvm for Ruby)来避免这类问题,请告诉我.
如果你只有一个小时,我建议重新启动.
在Xcode中构建objective-c项目有一个功能,称为自动引用计数.你的书没有使用它.
重新启动时,请在完成向导时创建项目时密切注意.你需要确保
使用自动参考计数
未被选中.
| 归档时间: |
|
| 查看次数: |
10696 次 |
| 最近记录: |