Category: iphone

Core Data and Booleans: Newbie Edition

UPDATE!
As pointed out by Jeff LaMarche and Julio Barros, there is an easier way to deal with Booleans in Core Data, and it is using Wolf Rentzsch‘s http://rentzsch.github.com/mogenerator/

Original Post:
There are a couple of things that I had trouble with while using a boolean with Core Data. The first was how to update this attribute, and the second was how to properly test against it.

I have an attribute in one of my Core Data entities that is of type Bool in my .xcdatamodel called isDone.

When I first tried to update the value to YES, I tried to do this:

This, quite rightly, gives the warning: “makes pointer from integer without a cast.” That is because Core Data does not support a boolean type. It will create your bool attribute with a type of NSNumber, which I could see when I looked at the header file for my item:

@property (nonatomic, retain) NSNumber * isDone;

So the correct thing to do was save the NSNumber value of NO or YES (0 or 1) by using numberWithBool:

The second wrinkle was when I tried to test the value of this attribute. I first wrote:

If (toDo.isDone)

The problem? This was always returning true! Because it was testing, basically, whether or not the NSNumber stored in the isDone property was nil or not. Even if its value was 0, if (item.isDone) evaluated to true.

What I did instead? Test against the boolValue

If (toDo.isDone.boolValue)

Hurray! And now I can get on with it!

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:

iPad: First Impressions

I wrote this entire blog on my iPad. It took twice the time to get it on the web as it took me to write it, and edit all images, in Pages on the iPad.

No headphones? Really?
The lack of headphones seems unnecessarily cheap, and very un-Apple. I mean, they gave us free water and free Starbucks in the line to get this thing, but no headphones with your iPad? LAME.

Ipad keyboard

It feels a little awkward not to have the tactile response. The keyboard also feels a little bit cramped. I am definitely not spreading my fingers out as much as I normally do on a real keyboard. I am, however, doing my best to type as i do on a normal keyboard (not looking at the keys, left fingers placed on ASDF).
Read more »

Zombies, demystifying the XIB, and console clearing: iPhone Cookbook Lessons

I’m on page 58 of the second edition of Erica Sadun’s “iPhone Developer’s Cookbook,” and here are the most important lessons I’ve learned so far:

  1. Zombies!
  2. What’s inside that XIB?
  3. The Clear Log Button

Setting NSZombieEnabled to YESZombies!
Did you know that, by default, your XCode project is NOT enabled to catch Zombies?  And by zombies, I mean objects that you have released, but then subsequently try to access?  THEY ARE ZOMBIES! They are the dead that still roam.  This is good for horror films, but very bad for your code.  But, by default, XCode’s debugger has no way to catch these nasties.

If you try and access a destroyed or released object, you’ll get back a cryptic objc_msgSend.  But!  If you ENABLE THE ZOMBIES as Sadun suggests, you’ll get back a much better message. In my case, I’m trying to access an array (via this call: CFShow([array self])) that I’ve already released. This gives me the following message in my gdb console:

2010-03-30 21:39:28.180 HelloWorld2[2398:207] *** -[CFArray self]: message sent to deallocated instance 0x1810260

interfacebuilderGetting inside those .xib files
Read more »

LouiseBrooks theme byThemocracy