I was seeing a very strange description for an NSMutableArray object in XCode. Instead of viewing the array’s count, as I expected, I was seeing some garbled message that said {(int)[$VAR count]} objects:

A quick google search pointed me to a conversation about this on stackoverflow. The key point in that link is this, made by Quinn Taylor:
it’s possible that the object has been reclaimed (either by -dealloc or GC) so check to make sure it’s retained if needed.
AH-HA!! I am screwing up my memory management again!
For some context, I went back to the Objective-C bootcamp chapter of the iPhone Developer’s Cookbook
, and sure enough, Erica Sadun talks about this on page 112:
Retaining objects set to autorelease allows them to persist beyond a single method.
The problem? My array was created by calling [NSMutableArray array], which returns an autoreleased NSMutableArray object. Thus, it was disappearing once I left the method where I created it.
Changing my code from:

To:

solved my problem. Huzzah!
In the course of doing recipes for the Erica/Alexis project, I have learned that there are several things I need to be sure to do before modifying any of the base templates Apple provides.
1. Remember to add the app delegate string to main
When starting a new project, I am often faced with a black screen. Despite the fact that this has happened to me three times now, it still takes me a bit of hair tearing before I remember it’s because I need to add the app delegate to the fourth parameter in the main method.

The solution to this, of course, would be to update my user templates so I don’t have to remember to do this every time.
2. Set the file’s owner to be the view controller
By default, the File Owner’s type is set to NSObject. When I have ViewControllers I want to use as a basis for my project, I need to change this so the File Owner’s type is set to my custom Root ViewController.

3. Remove the main xib line from info.plist
After changing (1) and (2), I was still getting this error: “2010-05-07 15:12:55.632 TwoItems[21829:207] Failed to load NSMainNibFile MainWindow.”
The problem was Read more »
The Erica/Alexis project is going quite well, despite my lack of new posts about it. I have a number of drafts in the queue, but for now, I give you visual evidence of the progress I’ve been making. Yes, I really love mini post-it notes:

Filed in: Erica/Alexis project, ipad, iphone, programming | am | May 9, 2010 | View Comments
Tags: Erica/Alexis project, highlighers, ipad, iphone, objective-c, post it notes, programming, reading is good for you, RTFM
Through the course of my progress through the iPhone Developer’s Cookbook
, one thing is becoming increasingly clear to me: I did not understand fundamentals of Objective-C.
I really thought that my foundations in java, C#, and even C (thank you, Operating Systems with Jason Nieh) was enough. I breezed through lists of the differences, read some code, and I was done, thankyouverymuch. I even skimmed the “Objective-C bootcamp” section and deemed it irrelevant for me.
But with this challenge, I’ve promised myself to read every page of this book. And you know what? I really needed to RTFM. Why?
- I didn’t realize Objective-C is dynamically typed (even though I should have realized this with all the id variables floating around!)
- I didn’t know selectors were basically just another way of saying “method name”
- I didn’t know that if you do a child-to-parent assignment, like assigning an NSMutableArray to an NSArray, you’ll get the somewhat vague “assignment from distinct Objective-C” warning
- I didn’t know you should always check for if (!self) in your init methods because in case of memory warnings, [super init] can return nil
- I didn’t know that Apple has a standard on Class methods: any object returned by a class method is returned to you already autoreleased
It’s little things like these that can really trip me up. So far, the Erica/Alexis project is incredibly rewarding.
Filed in: Erica/Alexis project, apple, education, technology | am | April 20, 2010 | View Comments
Tags: erica sadun, Erica/Alexis project, ipad, iphone, objective, Objective-C basics, RTFM