ramblings, musing and code snippets from shawn veader
I installed the 3.2 beta the other day to play with the new iPad simulator. (Neat stuff… more on that later.) But I tried working on one of my many half-completed iPhone apps the other night and ran into a few interesting problems.
The first problem I encountered was that the credentials in my app were not saving to the user defaults. I scratched my head a few times with this but did get some good testing out of it.
The second problem was the one that eventually led me to hitting Google in search of answers. After getting past some bugs I uncovered by not having user credentials, my app tried to load a standard table view. This table view has a custom cell loaded from a NIB. When the app tried to load this NIB, I was greeted with this wonderful message in the console.
uncaught exception ‘NSInvalidUnarchiveOperationException’, reason: ‘*** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (UITableViewCellContentView)’
A few Google searches later and I found this response over on StackOverflow. However, I found it hard to believe that all of a sudden I needed to declare a class that was supposed to be built into the framework. I then started poking at XCode and the simulator and noticed something strange….
I had opened my project from the console (yes, I’m *that* guy) with the “open” command as I always do. Unbeknownst to me this opened the newer XCode out of the alternate install. This turned out to be the root of all my problems. I opened /Developer/Applications/XCode.app and BOOM everything started working again.
So if you’re running dual development environments, watch out!
I never seem to find enough time to be in Obj-C land long enough to develop muscle memory so there are things that consistently get me.
NSDictionary creation is backwards:
NSDictionary *stuff =
[NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1",
@"value2", @"key2", nil];
In Ruby-land (where I’ve been for quite some time) it would be:
stuff = { :key1 => "value1", :key2 => "value2" }
Almost forgot!
I also almost always forget the nil at the end of an NSDictionary or NSArray declaration.
For instance:
NSArray *myList = [NSArray arrayWithObjects: @"foo", @"bar", @"baz", nil];
I continually forget that trailing nil, but it should be obvious since C is under the covers after all.
No, they’re not here to eat your brain this time. They are here to save it.
So you’re happily coding along in Obj-C and developing the next big iPhone app. You build and run in the simulator only to see it crash and give EXC_BAD_ACCESS in the console. You then spend a few minutes to a few hours (depending on how persistent you are) debugging and trying to chase down the problem (which, by the way, is usually trying to send a message to a released object). Compound this by having a multithreaded application (you are using threads, right?) and you can start to feel the frustration building.
Now envision some zombies coming to help. Yes, zombies.
Well… not real zombies of course.
Objective-C was kind enough to include an awesome environment variable you can set that will leave around a dummy object for everything that is released so you can see where that EXC_BAD_ACCESS is coming from.
The environment variable is NSZombieEnabled. Edit the executable options in XCode and create a new environment variable named NSZombieEnabled and set the value to YES. It should look like this:

Now build and run and see what you get. Enjoy!
OK, so while building an iPhone app last night I ran into a little snag. We are using an animated GIF on the loading screen to allow the user to see something pretty while they wait.
Being naive, I assumed the UIImageView would display the animated GIF. Well… I was partially right. It does display the GIF but only the first frame.
Then the Google hunt began…
After some searching, I had found that you can set the animatedImages property of a UIImageView to a NSArray that contains each frame of the animated GIF and then call the startAnimating method to “play” it.
OK, great…. now how do I get the frames out? After more Googling I just tried Preview.app on a wild hair. I’m glad to report that it shows the animated GIF but in the drawer of the app, it also has each frame. Simply drag each of these out and boom! you’re set.
Now for the code sample.
UIImage *frame0 = [UIImage imageNamed:@"frame0.png"];
// ... more frames here ...
UIImage *frameN = [UIImage imageNamed:@"frameN.png"];
// animatedGif is a UIImageView initialized in your NIB or elsewhere.
animatedGif.animatedImages = [[NSArray alloc] initWithObjects:frame0
....
frameN,
nil];
[animatedGif startAnimating];
There are a few other things you can play with like the animatedDuration and animatedRepeatCount properties. But you can figure those out.
And a link to the UIImageView documentation for completeness… UIImageView
So I’m back on Safari, for the moment, (no offense Firefox) and I just wanted to pass along two plugins that you must install.
Click-to-Flash
http://github.com/rentzsch/clicktoflash/tree/master
This replaces any flash on a website with a little logo that says “Flash”. If you actually want to see the flash you just click it and it loads. Works very well to keep the browser from chewing up all your computing resources running Flash. (Adobe: why is Flash so horrible?)
AdBlock
http://burgersoftware.com/en/safariadblock
Recent addition for me but blocks ad content for a more pleasant browsing experience.
OK, so I’ve had my head in and out of books lately trying to learn obj-C and Cocoa. So far it’s not too bad. Kinda fun to be back into a little more strict C-style world, while still maintaining some cool OO features.
My biggest gotchas/gripes I’ve found so far?
1) Having to add a nil to the end of a declared NSArray or NSDictionary (or their mutable variants).
[NSArray arrayWithObjects:@"1", @"2", @"3", nil];
That just seems like something that could be abstracted away for you…
2) Declaring a NSDictionary with keys and values is backward from what I would expect from Ruby land.
// what I expect
[NSDictionary dictionaryWithObjectsAndKeys:
@"key1", @"value1", @"key2", @"value2",nil];
// what reality is
[NSDictionary dictionaryWithObjectsAndKeys:
@"value1", @"key1", @"value2", @"key2",nil];
3) And as you can see from the examples above… the biggest gotcha of all is that to declare a string you have to prefix it with @.
(Hopefully I’ll start actually putting up stuff on this tumblelog again now…)
Yes, I’m just one of the many who have fallen into the stupid Brazilian Orkut fake kid pages. There is a whole profile based off images from my Flickr stream.
http://www.orkut.com/Main#Album.aspx?uid=6447389076309092886&aid=1230630259
http://www.orkut.com/Main#Album.aspx?uid=499062161829329821&aid=1
I know I could toggle the “Friends & Family” setting on Flickr but I have too many people who look at my stream who are real friends and family that I don’t want to have to send a link or require them to sign up to see the pictures.
Of course Google, the owner of Orkut.com, is of absolutely no help. Reporting abuse on the site gives me this wonderful canned response:
Thank you for your reporting of abuse on Orkut on “2009-01-06”.
Based on our review and consideration of Orkut’s terms of service, we understand that this content does not currently break any policies on Orkut. If you believe that a mistake has been made, please re-submit your complaint with additional information to help our support team better understand your concerns with this content.
Thanks Google.
Thanks!!!!?!?!
Glad they are so willing to help fight their site turning into a steaming pile of crap with pedophiles, etc.
Sigh, such is life on the interwebs.
Update: a friend of a friend works at Google and was able to get at least one of the accounts nuked this morning.
Well it looks pike I forgot about my tumblog for some time now. Guess it is time to resurrect it.
Stay tunes for ramblings about languages I’m learning at the moment.
First up…. Erlang.
Having heard a blurb on an endless page plugin on the RailsEnvy podcast, I decided to check it out. I wasn’t happy with how the plugin worked, so I whipped up something similar.
(Original post mentioned on RailsEnvy: link)
I decided most of what was needed was a mix of the wonderful will_paginate plugin and some Javascript. Thus endlesspage.js was born.
After including endlesspage.js in your layout, you should be able to do follow along below on how to set it up.
In the Controller: pastie
In the Views: pastie
Here is the file: endlesspage.js
(Sorry, but I couldn’t get Tumblr to cooperate with dumping in code.)
Let me know if you find this helpful…
UPDATE: I was informed (and confirmed myself) that the gem version of will_paginate doesn’t have the page_count method. The substitute method is total_pages.