Posts tagged: objective-c

Basic Memory Management: EFF-ing up my arrays

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!

Issues & Solutions for getting started in iPhone Projects

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 »

Erica/Alexis Project: A Visual Update

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:

Learning to write iPhone Apps, and the intersection of Apple and LOLCATS

There are three main resources I’ve been using to teach myself Objective-C, Cocoa Touch and iPhone programming:

The cookbook is excellent as a reference, and as a human-readable, easy-analogy alternative to the lecture slides.
The class itself holds your hand with their assignments, and I have been slowly builing up my Obj-C development skills through their carefully thought-out assignments.

Finally, the ADC videos provide an excellent window into what iPhone OS 3.0 can do, and code samples to help you start actually doing it.

Now, you may be asking, “that’s all fine and good, but where do the LOLCATS come in?”

SO, you only need look at someone and you can quickly make an assessment if they’re an apple or a PC person.  Apple’s TV marketing depends on it.  But I would like to argue that you need only look at their EDUCATIONAL SLIDE MATERIAL to make the same assessment.

Sure, this isn’t from WWDC, but this is on iTunes to help people understand how to use iPhone OS 3.0.  If I wasn’t a Mac convert before, this truly would have made me a believer:
applelolcats.png

Brilliant.  Bloody fucking brilliant.

LouiseBrooks theme byThemocracy