简体   繁体   中英

autorelease alternative on ios5

What is the alternative to autorelease in ios5? Previously the following method for table views would work:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    NSUInteger row = [indexPath row];

    static NSString *TableIdentifier = @"TableIndentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TableIdentifier];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault 
                                  reuseIdentifier:TableIdentifier]autorelease];
    }

    cell.textLabel.text = [arrAccounts objectAtIndex:row];
    return cell;
}

How ever now i get a message "ARC forbids" and "autorelease is unavailable"... what is the work around for this?

simply remove the autorelease, ARC does the work for you

cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault 
                                  reuseIdentifier:TableIdentifier];

It's damn magic

Remove the autorelease call. AFAIK the compiler is smart enough to realize that it should be autoreleased and synthesizes the appropriate calls for you.

If you don't want to make the required changes for ARC to the current file you can disable ARC for a specific file using a new -fno-objc-arc compiler flag for that file. ARC is enabled using a new -fobjc-arc compiler flag. You can choose to use ARC on a per-file basis if it's more convenient for you to use manual reference counting for some files. More info: http://developer.apple.com/library/ios/#releasenotes/ObjectiveC/RN-TransitioningToARC/_index.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM