What is a typedef enum in Objective-C?

I don’t think I fundamentally understand what an enum is, and when to use it. For example: typedef enum { kCircle, kRectangle, kOblateSpheroid } ShapeType; What is really being declared here? 13 s 13 Three things are being declared here: an anonymous enumerated type is declared, ShapeType is being declared a typedef for that anonymous … Read more

Shortcuts in Objective-C to concatenate NSStrings

Are there any shortcuts to (stringByAppendingString:) string concatenation in Objective-C, or shortcuts for working with NSString in general? For example, I’d like to make: NSString *myString = @”This”; NSString *test = [myString stringByAppendingString:@” is just a test”]; something more like: string myString = “This”; string test = myString + ” is just a test”; 30 … Read more

How do I check if a string contains another string in Objective-C?

How can I check if a string (NSString) contains another smaller string? I was hoping for something like: NSString *string = @”hello bla bla”; NSLog(@”%d”,[string containsSubstring:@”hello”]); But the closest I could find was: if ([string rangeOfString:@”hello”] == 0) { NSLog(@”sub string doesnt exist”); } else { NSLog(@”exists”); } Anyway, is that the best way to … Read more

performSelector may cause a leak because its selector is unknown

I’m getting the following warning by the ARC compiler: “performSelector may cause a leak because its selector is unknown”. Here’s what I’m doing: [_controller performSelector:NSSelectorFromString(@”someMethod”)]; Why do I get this warning? I understand the compiler can’t check if the selector exists or not, but why would that cause a leak? And how can I change … Read more

How do I sort an NSMutableArray with custom objects in it?

What I want to do seems pretty simple, but I can’t find any answers on the web. I have an NSMutableArray of objects, and let’s say they are ‘Person’ objects. I want to sort the NSMutableArray by Person.birthDate which is an NSDate. I think it has something to do with this method: NSArray *sortedArray = … Read more