Showing posts with label XCode. Show all posts
Showing posts with label XCode. Show all posts

Tuesday, February 09, 2010

OCMock for the iPhone

I was using OCMock for testing on the iPhone, but for some strange reason, a configuration I had once done disappeared. I tracked down the tutorial I had used to set up OCMock, and went through it again to get back my tests to working condition again.

I don't want forget this link anymore, so I'm blogging it :)

Monday, November 23, 2009

Localization/Internationalization/i18n for iPhone apps

I have found this internationalization guide on how to make your iPhone app behave appropriately according to the iPhone's language preference. Very easy to get started. Ideally the strings are externalized as from day 1. It's a bit time consuming externalizing them later on :(

Sunday, October 25, 2009

Updating the Provisioning Profile

When my provisioning profile expired, I had to create another one. But I had problems hooking it with the project. This how-to saved the day.

Tuesday, September 29, 2009

Unit testing on the iPhone SDK

I have been busy preparing lectures (still am) but I'm still alive :)

Introduction

I realised that I was adding code to the iPhone project more like in a prototyping stage. I wasn't doing any tests but I still tried to organize the classes as best as I could. Now I'm starting to loose confidence when I'm going to add some features. Not a good feeling. I want to switch to TDD (Test Driven Development), where you first write a failing test, and then write the production code. The excellent side effect of this is that the design of the classes are automatically decoupled. However I need to first convert my project to be covered by tests. Found an interesting book called "Working Effectively with Legacy Code" where it gives a lot of tips on how to breakdown classes, etc. I'm still reading it in my free time, but I will soon be putting the tips to work.

Setting up test harness
I searched for setting up a test harness in XCode. Version 3 supports unit tests using the SenTesting classes. I found a presentation and an Apple support page to set up a test harness. It also describes for setting up functional testing, however I will be only using unit (logic) tests for now.

Some tips to finalize the setup

Remember to drag any .m files into the Compile Sources in the logic tests target and also any libraries.
Also edit the Active target LogicTests and under Build tab, in Gcc 4.2 - Language section, turn on Precompile Prefix Header and also set the Prefix Header to _Prefix.pch
It is very important to this as otherwise it will give you loads of errors like could not find CGPoint class, etc

NSLog...where are they output?
What about logging when running the tests? Since to execute the unit tests you just need to build the application, there is not console out from XCode, however you can view the output of NSLog statements in the Console application. Launch Console from Spotlight.

Code Coverage
I also wanted to have code coverage, to know how much of the code is being tests by the tests. I found an excellent tutorial on setting up code coverage. It uses CoverStory - a tool for viewing the results of code coverage.

Now I need to rewire my brain to think in tests...

Tuesday, July 28, 2009

LLVM/CLang static analyzer minor problem with iPhone SDK3

The solution is to just tell scan-build to use gcc 4.2.
The command would then be something like this
scan-build --use-cc=/usr/bin/gcc-4.2 -k -V xcodebuild

Bought xp-dev.com SVN service subscription

I required another repository as I'm doing a quick prototype of a very simple game I had done once with a friend of mine. I have decided to buy a subscription for xp-dev.com, the online SVN service. It has worked pretty well so far and when you upgrade they provide a backup service as well, besides no limitations (diskspace increased to 2g), and multiple repositories. 40$ is a good price for hassle-free SVN service which works without any problems in XCode.

Sunday, July 12, 2009

Selection List in UIKit

I also dared using a selection list using the UITableViewController class on top of openGL view. I used a modified version of the generic class by Jeff Lamarche. This video tutorial helped as well to get an idea of how the code is organised for UITableViews.

So now I got a pretty decent on-the-fly level editor for the game. I can also select powerups for enemy groups and draw the enemies paths, etc. Still needs polishing, but it's coming together. This week I will try do a decent level, but for now with just one enemy type, and no boss.

Saturday, May 23, 2009

random() on the iphone SDK giving same values

I obviously had changed the random seed with srand(time(NULL)) however when generating 4 random numbers they were always the same although always different with each run. I thought I was going insane as when I tried debugging it step by step the numbers generated were different.

After googling a bit I found that it is better to use arc4random(). That fixed it.

Breakpoints stopped working in XCode

Suddenl, the breakpoints stopped working. Usually I just clean all targets and empty XCode's cache. But this time that trick didn't work. Then I found this solution, to disable Load Symbols Lazily from XCode Preferences->Debugging. That worked like a charm.

Wednesday, May 20, 2009

Got my Apple Developer Program Activation Code

Yippeee! Finally after 3 weeks!

This morning I sent Apple an email telling them that this sending of the activation code was agrivating. I told them that I bought a macbook, switched from windows, bought an ipod touch, but I'm still waiting for the activation code. Later this afternoon I just received the activation code.

Setting up the device was quite straightforward. They provide a very helpful wizard-like experience. But then I got a CodeSign error when I tried Build&Go. I discovered that the Code Signing properties in the project were not set. I just had to select the developer provisioning certificate and presto... I was debugging my buggy prototype on my iPod touch :D

Saturday, May 02, 2009

Making reproducible bugs

I got some bugs lurking around related with collision detection. So the first rule when debugging is to make the bugs reproducible. I'm currently trying to record the user interactions and frame number at which they occurred, into an NSMutableArray, and then dumping it to NSDefaults when exiting the application (should be enough for now). Then I will load them back up when the application is relaunched. At the frame number at which the user interactions (basically lines) were originally made, I recreate the lines. Also I had to remove any randomness if I want that each time I play the recorded actions, I get the same outcomes (i.e. bugs). So the ball(s) will always start from the same position.

Will try to finish this interactions playback later on. Have to prepare for next week's lectures.

Friday, April 24, 2009

The pains of converting from Java to Objective-C

I'm still compiling a list of the annoyances I encounter when converting from Java to Objective-C, which I will publish soon. But so far the worst one was to be careful when using the math functions like abs instead of fabs! The abs function works with ints and if you try using it with a float, you are going to get some bogus result. Why why aren't such methods overloaded!?!

Wasted a good two hours trying to hunt down such a bug in some code which worked fine in actionscript.

Mental note: remember as well sinf, cosf, asinf, acosf

Migrating current actionscript code to Xcode... check :D
Next task...

Thursday, April 23, 2009

Refactoring in XCode needs improvement

I'm used to Eclipse refactoring, and the refactoring capabilities in XCode compare to Eclipse are abysmal to say the least. Ok, I know Java is much easier to parse, and so the refactoring tools are "easier" to do, but I would expect that at least renaming a field of an Objective-C class would be done across the header and implementation files, and not just the header file. So instead I have to the use the rename dialog box, which of course is very error prone.

Maybe I'm doing something wrong, but I don't see what that could be. I'm just selecting the field, Edit->Refactor->Rename.

Friday, April 17, 2009

Killing bugs before they happen on the iPhone

You can easily set up a Static Analyzer, which will check your Objective-C code for bugs, like memory leaks, dead assignments, etc, without actually running the app on the iPhone (that's why "static"). Check out this tutorial to setup the LLVM/Clang Static Analyzer for iPhone Apps.

You need to dirty your hands slightly with the Terminal to run the analyzer. You might want to add analyzer to your path to your .bash_profile so that you can run the analyzer from anywhere.

When you run the analyzer, you will see a bug report with links to your source files to show you the exact line where you have a bug. Sweet!


Tuesday, April 14, 2009

Adding an SCM SVN Repository to XCode

I needed to set up some subversion. Having a subversion (SVN), or any other source control management is very important. Besides backing up the code remotely, I can quickly diff with previous releases, commit with comments, tag files and code branches, etc.

I googled a bit for free SVN hosting and found XP-Dev.com. After creating my repository I set up XCode to know about my XP-Dev repository. That was a breeze, but then a problem crop up when I wanted to import my existing prototype in the repository. It was complaining about some SCM Error 155007.

Googled a bit more, and luckily some other guys had the same problems. They suggested to do the initial commit from the terminal. This did the trick:

svn import /path/to/project http://username@svn.xp-dev.com/svn// -m “Initial import”

Remember the to do the name when importing, otherwise you won't be able to do a proper checkout. After the import is done, you need to go to XCode>SCM>Repositories and do a checkout to a different directory. It should prompt you to automatically open the XCode project when it finishes.

To check if it's working fine, you can simply type something in some existing file and save, and you should see an M to the left of the Groups & Files sidebar, meaning it is modified and can then be committed at your will :D

Renaming an XCode Project

I found it is pretty painful to rename a project in XCode. Then I found that someone has done a script besides describing how to do it manually. Learn more on renaming an XCode project.