IBOutletCollection set ordering in Interface Builder

EDIT: Several commenters have claimed that more recent versions of Xcode return IBOutletCollections in the order the connections are made. Others have claimed that this approach didn’t work for them in storyboards. I haven’t tested this myself, but if you’re willing to rely on undocumented behavior, then you may find that the explicit sorting I’ve … Read more

Class method equivalent of -respondsToSelector:

Update after seeing your edit: A class object responds to respondsToSelector: just fine, as you’re probably aware. In a test application, I can do both of the following without any compiler warnings: NSLog(@”Responds to selector? %i”, [MyObject respondsToSelector:@selector(respondsToSelector:)]); NSLog(@”Responds to selector? %i”, [[MyObject class] respondsToSelector:@selector(respondsToSelector:)]); However, you’ve declared a protocol on your variable, so it … Read more

What is the difference between a __weak and a __block reference?

From the docs about __block __block variables live in storage that is shared between the lexical scope of the variable and all blocks and block copies declared or created within the variable’s lexical scope. Thus, the storage will survive the destruction of the stack frame if any copies of the blocks declared within the frame … Read more

iOS: store two NSMutableArray in a .plist file

Create an NSArray containing your two NSMutableArrays. NSArray *array = [NSArray arrayWithObjects:<#(id), …#>, nil]; Write the array to a file. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES); NSString *libraryDirectory = [paths objectAtIndex:0]; NSString *location = [libraryDirectory stringByAppendingString:@”/somefilename.plist”]; [array writeToFile:location atomically:YES]; Load the array from the file. NSString *path = [bundle pathForResource:@”file” ofType:@”plist”]; NSArry *array = (path … Read more

“Expression is not assignable” — Problem assigning float as sum of two other floats in Xcode?

The other answers don’t exactly explain what’s going on here, so this is the basic problem: When you write blackKey.center.x, the blackKey.center and center.x both look like struct member accesses, but they’re actually completely different things. blackKey.center is a property access, which desugars to something like [blackKey center], which in turn desugars to something like … Read more