How To Enable ARC in a Cocos2D 2.X Project

Discussion of the official tutorials published on raywenderlich.com. Please only discuss the official tutorials here - for general questions, use the General Discussion forum instead.

How To Enable ARC in a Cocos2D 2.X Project

Postby rwenderlich » Tue Nov 20, 2012 11:00 am

This is the official thread to discuss the following blog post: How To Enable ARC in a Cocos2D 2.X Project
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
User avatar
rwenderlich
Site Admin
 
Posts: 1776
Joined: Thu Dec 23, 2010 4:14 pm
Has thanked: 26 times
Been thanked: 186 times

Re: How To Enable ARC in a Cocos2D 2.X Project

Postby Romyilano » Wed Nov 21, 2012 2:41 am

Thank you so much for posting this! I almost gave up doing some of the Cocos2D tutorials, silly me. Other methods to make Cocos2D arc compatible were blowing up my computer.

Where would newbies be without this site?
Romyilano
n00b
 
Posts: 3
Joined: Fri Sep 07, 2012 9:00 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How To Enable ARC in a Cocos2D 2.X Project

Postby mojo » Wed Nov 21, 2012 8:18 am

great tutorial. This is exactly what I needed to get back to cocos2D. I stopped developing for cocos2d in the 0.9.8 era and when i started again after all this time it left me confused. Thanks for this tutorial.
mojo
Baby Hacker
 
Posts: 6
Joined: Tue Jun 14, 2011 6:40 am
Has thanked: 2 times
Been thanked: 0 time

Re: How To Enable ARC in a Cocos2D 2.X Project

Postby World of A » Wed Nov 21, 2012 8:34 am

I disagree flagging on a per-source-file basis with -fno-objc-arc. It is a way to do it, but it will be pretty hard to maintain your code when you update Cocos2d! Instead take a look at another approach : http://www.learn-cocos2d.com/2012/04/enabling-arc-cocos2d-project-howto-stepbystep-tutorialguide/

Here's a quote from Steffen in that tut:
Warning: Some recommend to use the -fno-objc-arc Compiler Flag to disable ARC on a per-source-file basis. This is only helpful if you have very few source code files which require this flag where an extra static library target would be overkill. Since you’ll have to add the flag to each cocos2d source code file individually – one-by-one – and there being anywhere between 100 and 150 source files, I strongly discourage going down this road. Plus it will be a maintenance nightmare whenever you upgrade cocos2d.
Image
World of A
[just fly]
http://www.worldofathesite.com
User avatar
World of A
Hacker
 
Posts: 22
Joined: Thu Apr 05, 2012 3:05 pm
Has thanked: 3 times
Been thanked: 5 times

Re: How To Enable ARC in a Cocos2D 2.X Project

Postby rwenderlich » Wed Nov 21, 2012 2:03 pm

@World of A: Heh, and I disagree with that :]

Code: Select all
Since you’ll have to add the flag to each cocos2d source code file individually – one-by-one – and there being anywhere between 100 and 150 source files, I strongly discourage going down this road.


That is actually untrue - if you select the files and hit "Enter" in Xcode you can set all of them at once.

So upgrading to a new version of Cocos2D is no problem, since setting that flag on the files only takes < 10 seconds. :]

I'm not saying the library approach is bad - there are some nice things about doing it that way - but this way has the advantage of being nice and easy.
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
User avatar
rwenderlich
Site Admin
 
Posts: 1776
Joined: Thu Dec 23, 2010 4:14 pm
Has thanked: 26 times
Been thanked: 186 times

Re: How To Enable ARC in a Cocos2D 2.X Project

Postby Pianisimo » Tue Feb 19, 2013 2:28 pm

I just updated cocos to latest version cocos2d-iphone-2.1-rc0a, followed all the steps, seems working fine but there is a warning in appDelegate.m which worries me.

inside the method:
Code: Select all
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   [director_ setDelegate:navController_];
}

the warning says:
sending 'UINAvigationController *_strong to parameter of incompatible type 'id<CCDirectorDelagete>'

Is this something I should ignore, or should I do anything else.
Pianisimo
n00b
 
Posts: 2
Joined: Tue Feb 19, 2013 2:19 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How To Enable ARC in a Cocos2D 2.X Project

Postby sir_seagill » Mon Apr 22, 2013 12:28 pm

I tried the static library approach... ran into errors. this method worked for me, so yes this is easier :)
Mark W - A causal Flash designer now learning cocos2d (let the fun begin ^_^)
User avatar
sir_seagill
Hacker
 
Posts: 15
Joined: Sat Dec 25, 2010 10:57 am
Has thanked: 1 time
Been thanked: 0 time

Re: How To Enable ARC in a Cocos2D 2.X Project

Postby RHerrema » Wed May 08, 2013 9:42 am

I've followed all the steps you've suggested, but when I build I get an error message: 'Expected ';' at end of declaration list' for this line in the AppDelegate.h file:

CCDirectorIOS *_unsafe_unretained director_; // weak ref

which seems strange, since the ';' is there. I'm using Xcode 4.5.2.
RHerrema
n00b
 
Posts: 2
Joined: Wed Feb 06, 2013 2:52 pm
Has thanked: 0 time
Been thanked: 0 time


Return to Official Tutorials

Who is online

Users browsing this forum: Google [Bot] and 4 guests