Friday, January 28, 2011

iPhone dev Stupidity 140: encode CGRect into NSUserDefaults

from stackoverflow:
There exists a pair of functions NSStringFromCGPoint and CGPointFromString. You can use these to produce an array of strings representing the points for serialization, and then convert back when you're finished.

Tuesday, January 18, 2011

Monday, January 17, 2011

iPhone dev Stupidity 137: Understanding instruments allocations


ObjectAlloc tracks all memory allocation and deallocation over the time your program is running.
The Living bytes, or Net bytes is how much memory your application is using at the time you select in the timeline. That will include leaked memory, since leaked memory is never deallocated.

#Living is how many allocations of a certain size/object type happened (and are still allocated). This is very useful when looking for leaks. For example, if you repetitively perform an action (like coming in an out of a modal view controller), and you see that #Living of an object grows by the same amount each time, then you’re probably leaking those objects. You can then confirm by drilling down and seeing the exact line of code that is allocating the objects, and even see the time index each one was created.

Overall bytes includes memory that has been released. It’s useful to track that number for performance optimization purposes, but not if you’re just trying to see your current memory footprint or look for leaks.

http://stackoverflow.com/questions/2154219/instruments-objectalloc-explanation-of-live-bytes-overall-bytes

Saturday, January 15, 2011

iPhone dev Stupidity 136: Two stage animation warning

Since iOS 4.0 you got this warning when present a camera picker controller:

Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations.

The real cause is from stackoverflow:
This message will appear if you have are presenting the UIImagePickerController within another UIViewController. Because it isn't pushed like a UINavigationController stack, there is confusion at the UIWindow level. I don't know if the warning is a problem, but to eliminate the warning you can do the following:

// self = a UIViewController
//

- (void) showCamera
{
cameraView = [[UIImagePickerController alloc] init];
[[[UIApplication sharedApplication] keyWindow] setRootViewController:cameraView];
[self presentModalViewController:cameraView animated:NO];
}

- (void) removeCamera
{
[[[UIApplication sharedApplication] keyWindow] setRootViewController:self];
[self dismissModalViewControllerAnimated:NO];
[cameraView release];
}

There’s also a good point for iOS 4.x:

Perhaps you are adding the root UIViewController's view as a subview of the window instead of assigning the view controller to the window's rootController property?