Why rename synthesized properties in iOS with leading underscores? [duplicate]

This is an artifact of a previous version of the Objective-C runtime. Originally, @synthesize was used to create accessors methods, but the runtime still required that instance variables had to be instantiated explicitly: @interface Foo : Bar { Baz *_qux; } @property (retain) Baz *qux; @end @implementation Foo @synthesize qux = _qux; – (void)dealloc { … Read more

Unbalanced calls to begin/end appearance transitions for

Without seeing more of the surrounding code I can’t give a definite answer, but I have two theories. You’re not using UIViewController‘s designated initializer initWithNibName:bundle:. Try using it instead of just init. Also, self may be one of the tab bar controller’s view controllers. Always present view controllers from the topmost view controller, which means … Read more

When to use enumerateObjectsUsingBlock vs. for

Ultimately, use whichever pattern you want to use and comes more naturally in the context. While for(… in …) is quite convenient and syntactically brief, enumerateObjectsUsingBlock: has a number of features that may or may not prove interesting: enumerateObjectsUsingBlock: will be as fast or faster than fast enumeration (for(… in …) uses the NSFastEnumeration support … Read more

Handling applicationDidBecomeActive – “How can a view controller respond to the app becoming Active?”

Any class in your application can become an “observer” for different notifications in the application. When you create (or load) your view controller, you’ll want to register it as an observer for the UIApplicationDidBecomeActiveNotification and specify which method that you want to call when that notification gets sent to your application. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(someMethod:) … Read more

How can I use NSError in my iPhone App?

Well, what I usually do is have my methods that could error-out at runtime take a reference to a NSError pointer. If something does indeed go wrong in that method, I can populate the NSError reference with error data and return nil from the method. Example: – (id) endWorldHunger:(id)largeAmountsOfMonies error:(NSError**)error { // begin feeding the … Read more

How can we programmatically detect which iOS version is device running on? [duplicate]

Best current version, without need to deal with numeric search within NSString is to define macros (See original answer: Check iPhone iOS Version) Those macros do exist in github, see: https://github.com/carlj/CJAMacros/blob/master/CJAMacros/CJAMacros.h Like this: #define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame) #define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending) #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] … Read more

How do you use NSAttributedString?

When building attributed strings, I prefer to use the mutable subclass, just to keep things cleaner. That being said, here’s how you create a tri-color attributed string: NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@”firstsecondthird”]; [string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,5)]; [string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(5,6)]; [string addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(11,5)]; typed in a browser. caveat implementor Obviously … Read more

Design for Facebook authentication in an iOS app that also accesses a secured web service

I just dealt with this myself, and here’s the part that bit me: In your step 5… It’s possible for a user to register for an account with you entirely separate from their Facebook ID, right? Then some other time they log in with Facebook…. And you just created them a second account and lost … Read more