views:

406

answers:

3

I'm writing my first iPhone app, so there is a lot of guessing about how things work. The objC memory model takes a while to get used to. After adding some code I got stuck in applicationDidFinishLaunching. The app was crashing while sending a message to an object which I was sure should have been created at that point in the code. The message receiver could not have been simpler, it was just a print statement for debugging:

NSLog("got message")

After trying a whole bunch of things, I finally decided to delete the debug statement even though I knew it wouldn't change anything. It started to work again. The print statement should have been

NSLog(@"got message")

Oh well. What similar situations have you been in?

A: 

Wrong tree barking, oh yeah. Sometimes the XCode cache can go bad, resulting in odd behaviour. Some things I check when it all seems to be going horribly wrong.

Nuke the cache : click XCode - Empty Caches... If no effect, shutdown XCode, if still no effect, reboot.

Sometimes I will mistakenly add a new file to my unit test target and not my actual, most recently I added a new view xib but when I tried to load the view, it complained about not having a view set. Checking in IB shows it is all setup and ready. Finally I checked the files info screens (CMD + I). Targets showed the file in the unit test target, but not the actual.

Those are the two most recent odd fixes I have had to find.

Ryan Townshend
+1  A: 

This week, actually. I wrote a very simple little TCP app and spent all day Tuesday trying to understand why the server wouldn't respond to my perfectly formed queries. After a number of hours and some Wiresharking, I eventually found my mistake:

rc = send( sock, data, length, 1 );

should have been

rc = send( sock, data, length, 0 );

I had been inadvertently sending out-of-band packets all day. Duh.

Graeme Perrow
+2  A: 

Wrong tree? Hours? Try barking in the wrong forest, for a month. :-(

Early in CamelBones' development, I discovered that I had a need to take arguments passed to a Perl method, and use them to set up a stack frame to pass to a C function. I wanted to do this dynamically, at run-time. So, I downloaded some PPC assembler introductions and reference materials, studied the details of Mac OS X's ABI, and in about a month or so I had it working.

Quite proud of my accomplishment, I showed it to a colleague - who crushed me with five little words: "Why didn't you use libffi?"

Still, I thought, at least I've learned a new skill. It wasn't all wasted effort. Then, less than two years later, Apple switched to Intel chips. Ah well, at least I had fun.

Sherm Pendley