How do you enable ARC project-wide in Xcode 4.2

“ARC is available in Xcode 4.2, currently in beta, and only when compiling with Clang (a.k.a. “Apple LLVM compiler”). The setting is called, obviously enough, “Objective-C Automatic Reference Counting”. Turn it on, and off you go. If you’re working on existing code, changing this setting will produce an enormous quantity of errors. ARC not only … Read more

Sound overlapping with multiple button presses

Declare your AVAudioPlayer in the header the viewController ( don’t alloc a new one each time you play a sound). That way you will have a pointer you can use in a StopAudio method. @interface myViewController : UIViewController <AVAudioPlayerDelegate> { AVAudioPlayer *theAudio; } @property (nonatomic, retain) AVAudioPlayer *theAudio; @end @implementation myViewController @synthesize theAudio; – (void)dealloc … Read more

GPS coordinates in degrees to calculate distances

Why don’t you use CLLocations distanceFromLocation: method? It will tell you the precise distance between the receiver and another CLLocation. CLLocation *locationA = [[CLLocation alloc] initWithLatitude:12.123456 longitude:12.123456]; CLLocation *locationB = [[CLLocation alloc] initWithLatitude:21.654321 longitude:21.654321]; CLLocationDistance distanceInMeters = [locationA distanceFromLocation:locationB]; // CLLocation is aka double [locationA release]; [locationB release]; It’s as easy as that.

How can I find out if the iPhone user currently has a passcode set and encryption enabled?

Disclaimer: This answer was valid until ios 4.3.3 If data protection is turned on, a newly created file will have a nil NSFileProtectionKey by default. If data protection is turned off, a newly created file will have a NSFileProtectionNone NSFileProtectionKey by default. Thus, you could detect the presence of file protection with the following code: … Read more