Welcome to my blog.
Always set NSError pointers to nil, Duh!
This is one of those errors that just make you go, duh!
Can you spot the problem with the following two snippets of code?
Snippet 1
NSError *error;
if (![someObject performFetch:&error])
NSLog(@"%@: %@", [error description], [error userInfo]);
Snippet 2
NSError *error;
if (![self.someObject performFetch:&error])
NSLog(@"%@: %@", [error description], [error userInfo]);
At first this does not appear to be a problem, but what if someObject is nil in the first case or the accessor self.someObject returns nil in the second? If either is nil then the message is sent to the nil object which will cause the conditional to fire (a message sent to the nil object returns 0 or nil). Now when error is used it has an uninitialized value, which will probably cause things to blow up, but now always.
The solution to initialize error to nil,
NSError *error = nil;
if (![self.someObject performFetch:&error])
NSLog(@"%@: %@", [error description], [error userInfo]);
Or in some cases add a check for the NSError also,
No Love in the App Store
One of the problems, the main problem. of Apple's App Store is hierarchy.
What? What does structure have to do with it. I am not talking about structure as in a folder hierarchy, but more to do with the pecking order. I have to explore this idea a little before I can tie it to the App Store.
I am an Indie developer. I don't do this for no other reason but that I love crafting software. I am in someways like that stereotypical computer geek. I dislike hierarchy. The hierarchy in the pecking order. I want to do things for the heck of it, because I love to do them, to explore, to learn. In some ways this is antiauthoritarian. It is the way of the creative.
Becoming part of the pecking order starts to define who you are. It becomes a status thing. It defines your position in the company. You start making decisions with regard to the hierarchy. You might not even realize this, but how many decisions are made because of your place in the company, of your place in the hierarchy. Think about it.
A Simple Way to Animate a UIBarButtonItem
My first pass solution to animate a UIBarButtonItem was to initialize it's custom view with a UIImageView. The UIImageView can then be set up for animation with multiple images. Calling startAnimaiton/stopAnimation on the UIImaveView will then animate. This is great for animating buttons in tool and tab bars.
One problem is that the when initializing the UIImageView into the UIBarButtonItem, the UIBarButtonItem does not respond to touch events. Yuk.
A simple solution is to initialize the UIBarButtonItem custom view with a UIButton, then touch events for the UIBarButtonItem item are handle correctly.
But the UIButton does not have a way to use a UIImageView only UIImages. We want to use the UIImageView for its simple animation.
The solution is to add the UIImageView as a subview of the UIButton.
Here is the code.
NSArray *images = [NSArray arrayWithObjects:
[UIImage imageNamed:@"image0.png"],
[UIImage imageNamed:@"image1.png"],
nil];
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image0.png"]];
How to Debug iPhone Unit Tests
[Updated the troubleshooting section 10/4/2009]
The unit tests are finally set up for the iPhone. You can start doing some Test Driven Development, but one is failing. I've read Apple's documentation, but how do I debug the blasted thing?
NSLog messages can be scattered throughout the code. Their output is sent to the console, but this is a pain. There must be a better way.
This is one area that needs to be improved in Xcode. There is not even documentation on how to debug unit tests.
Here's how to do it.
The following assumes that you have set up the unit tests using the templates in Xcode and follows along with Apple's example in their iPhone Development Guide. If you have not already set up your units test then the iPhone Development Guide is a good place to start. I am also using Xcode 3.2.
Three steps that need to be performed.
1. Setup a target that contains the unit tests, but does not run them.
2. Setup the otest executable to run the tests.
3. Setup the otest environment so that otest can find your unit tests.
Hello World
What else should a geeky programmer's first post be?
