AutoLayout: removeFromSuperview / removeConstraints throws exception and crashes hard

I had an (extensive) conversation with an Apple engineer about this crash. Here are the two most probable causes: You have an invalid constraint, such as view1.left = view2.left + 20 where view2 is unexpectedly nil, or has a multiplier of 0. Be sure to double (and triple) check your constraints to make sure that … Read more

Weak Reference to NSTimer Target To Prevent Retain Cycle

The proposed code: __weak id weakSelf = self; timer = [NSTimer scheduledTimerWithTimeInterval:30.0f target:weakSelf selector:@selector(tick) userInfo:nil repeats:YES]; has the effect that (i) a weak reference is made to self; (ii) that weak reference is read in order to provide a pointer to NSTimer. It won’t have the effect of creating an NSTimer with a weak reference. … Read more

What is the difference between Objective-C automatic reference counting and garbage collection?

As I describe in my answer here, ARC can provide the best of both manual memory management and tracing garbage collection. It mostly removes the need for a developer to track manual retains, releases, and autoreleases on Objective-C objects, yet avoids the need for a garbage collector process which can use up limited resources on … Read more

AVAudioPlayer not playing any sound

I found the solution and it’s related to something I didn’t mention and didn’t think about: I’m compiling with Automatic Reference Counting (ARC). ARC inserts a release call to the audio player, so it’s deallocated right after leaving the method where it is created. It has nothing to do with AVAudioPlayer but with ARC. In … Read more

NSArray of weak references (__unsafe_unretained) to objects under ARC

As Jason said, you can’t make NSArray store weak references. The easiest way to implement Emile’s suggestion of wrapping an object inside another object that stores a weak reference to it is the following: NSValue *value = [NSValue valueWithNonretainedObject:myObj]; [array addObject:value]; Another option: a category that makes NSMutableArray optionally store weak references. Note that these … Read more