Updated: Fixing Warnings in Cocos2d rc0.99 (prerelease) “Cocos2d with Box2D” template in Xcode

Some of the warnings of generated by the “The Cocos2d  and Box2d” template have be fixed in rc0.99 (prerelease).  Below is how to fix the remaining warnings.

1. To fix the “has different visibility” warning, add “-fvisibility=hidden” inside the Projects-> Edit Project Settings under the Build Tab in Other C Flags.  If the Other C Flags does not exist, add OTHER_CFLAGS under the “User-Defined” section of the Build Tab and add “-fvisibility=hidden” as its value.

An issue with Cocos2d Google code has been filed on this issue.

2. To fix the “Comparison is always true” warning generated from this line:

b2Assert(0 <= cache->count && cache->count <= 3)

make the following change since |count| is an unsigned int, it is never less than zero:

b2Assert(0 == cache->count && cache->count <= 3)

An issue with Box2D Google code has been filed on this issue.

Fixing the Warnings in the “Cocos2d with Box2d Template” in Xcode

The Cocos2d  and Box2d template generates a lot of warnings when compiling in Xcode with gcc.  Below are some of the most common warnings and how to fix them.  These fixes have been validated for Cocos2d 0.8.2 and 0.9 alpha.

1. To fix the “Statement has no effect” warning, in b2Settings.h change:

#define B2_NOT_USED(x) x
to 
 #define B2_NOT_USED(x) (void)x

2. To fix the “has different visibility” warning, add “-fvisibility=hidden” inside the Projects-> Edit Project Settings under the Build Tab in Other C Flags.

3. To fix the “Comparison is always true” warning generated from this line:

b2Assert(0 <= cache->count && cache->count <= 3)

make the following change since |count| is an unsigned int, it is never less than zero:

b2Assert(0 == cache->count && cache->count <= 3)

Starting a new XCode project with SVN version control

  1. Make a new project or use an existing project
  2. Delete the build file in the project directory.  Version control is not need on the build files.
  3. Go to: Projects->Edit Project Settings and click on General Tab
  4. Select “Custom location” under “Place Build Projects In” and select a directory that is not used for any of your projects.  (e.g. /Users/Code/Development/build/_ProjectName)
  5. Select “Build products location” under “Place Intermediate Build Projects In” and select a directory that is not used for any of your projects.
  6. Click on the “Configure Root and SCM” and select Subversion and select the repository (this assumes you have already set up a SVN repository)
  7. Close the project
  8. In XCode, SCM->Repositories and select the repository that you want to use for your project
  9. Navigate to the directory that you will store the project (e.g. Projects/NewProject/trunk)
  10. Import the entire project directory
  11. Checkout the entire project directory from SVN to the working directory (e.g. /Users/Code/Development/WorkingDirectory/) .  Click on open project if prompted
  12. Delete Project folder that was imported and is not under version control.
  13. Start coding and make sure to commit changes and add new files to the repository.

How to change the name of an Xcode iPhone Project

Change the name of an Xcode project is not as straightforward as it may seem.

Step-by-step instructions to change the name of an Xcode project

  1. Download and run this program.
  2. In the project folder, manually rename the AppDelegate .h and .m file (e.g. oldAppNameAppDelegate.m to newAppNameAppDelegate.m)
  3. In main.m, change the app delegate: int retVal = UIApplicationMain(argc, argv, nil, @”oldAppNameAppDelegate“);  to int retVal = UIApplicationMain(argc, argv, nil, @”newAppNameAppDelegate“);
  4. In newAppNameAppDelegate.h change:  @interface oldAppNameAppDelegate : …  to @interface newAppNameAppDelegate : …
  5. In newAppNameAppDelegate.m change: #import “oldAppNameAppDelegate.h” and @implementation oldAppNameAppDelegate to #import “newAppNameAppDelegate.h” and @implementation newAppNameAppDelegate
  6. Under the executables, rename the executable from “oldAppName” to “newAppName
  7. At this point the project should compile and run with any errors.  You might also want to go to Edit->Find->Find in Project… and replace all other instances of oldAppName with newAppName that might appear in comments.