ios: 'release' is unavailable: not available in automatic reference counting mode [duplicate]

原文地址:http://stackoverflow.com/questions/22996437/release-is-unavailable-not-available-in-automatic-reference-counting-mode

I'm learning how to program on the iOS operating system using the book "Head first iPhone and iPad development" (second edition).

Screenshot

When I try to compile the code from the book, I get the error that the use release keyword is not allowed in reference counting mode.

Do I have to explicitly release the memory in this case? If yes - how?

shareimprove this question

marked as duplicate by Josh CaswellCalebMick MacCallum Apr 10 '14 at 19:05

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

 
    
With ARC (introduced with iOS6 or iOS5), let's say it's managed just before the compilation. – Larme Apr 10 '14 at 18:47 
    
With ARC enabled you don't have to, your book is probably a couple of years old. – pNre Apr 10 '14 at 18:48
1  
Better get an up to date book, lots of things have changed. – Fructose Apr 10 '14 at 19:25

2 Answers

Sounds like your book predates ARC.

You can develop an application with the same code if you disable ARC in the project settings:

How to disable ARC

But... ARC has been out for a while, and iOS changes fast. If the book doesn't mention ARC, it's a probably sign that it targets a version of the iOS SDK less than 5.0, which is not necessarily the best way to learn iOS development these days.

You can roughly translate to an ARC environment by just removing [super dealloc]retainrelease, and autorelease from the code you see. But it's valuable to understand why those are there in the first place and why they're no longer necessary with ARC.

 

posted on 2016-09-27 15:19  ZhYQ_note  阅读(399)  评论(0编辑  收藏  举报

导航