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

Xcode – How to fix ‘NSUnknownKeyException’, reason: … this class is not key value coding-compliant for the key X” error?

I’m trying to link a UILabel with an IBOutlet created in my class. My application is crashing with the following error. What does this mean? How can I fix it? *** Terminating app due to uncaught exception ‘NSUnknownKeyException’, reason: ‘[<UIViewController 0x6e36ae0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key XXX.’ 7 75

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

Transport security has blocked a cleartext HTTP

What setting do I need to put in my info.plist to enable HTTP mode as per the following error message? Transport security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app’s Info.plist file. Assume that my domain is example.com. 2 29 Use NSAppTransportSecurity: You … Read more