MKMapSnapshotter initWithOptions nullability

MKMapSnapshotter has the following constructor (within NS_ASSUME_NONNULL_BEGIN): – (instancetype)initWithOptions:(MKMapSnapshotOptions *)options NS_DESIGNATED_INITIALIZER; Which means an options param must be supplied. However the documentation contradicts this, stating “If you specify nil for this property, the snapshotter uses a set of default options that capture an image of the current user’s country”, thus Read more…

New Way to Override NSManagedObject Properties

There is a new, yet not very well-known way to override NSManagedObject properties without needing to manually call KVO methods willChangeValueForKey etc. This is achieved using dynamic accessors prefixed with managedObjectOriginal as follows: Department.h @interface Department : NSManagedObject @property (nullable, nonatomic, copy) NSString *name; @end Department.m @interface Department (DynamicAccessors) – (NSString Read more…

Common Init for a UIViewController Subclass

When creating a UIViewController subclass, e.g. in a framework, which you require to support being created from both storyboards and code, it is useful to implement initialisation which works for both. That can be achieved with a common init routine as follows: – (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super Read more…

Modern way to register NSUserDefaults

Here is a modern way to register user defaults. It uses dispatch_once to ensure the registration only happens once and performs it lazily on the first access. Keeps your defaults all on the one place. Also it is implemented as a global block in the class. NSInteger (^countBeforeAlerting)(void) = ^NSInteger(void) Read more…

Default behaviour of UISplitViewController collapseSecondaryViewController

The documentation for UISplitViewControllerDelegate collapseSecondaryViewController says: When you return NO, the split view controller calls the collapseSecondaryViewController:forSplitViewController: method of the primary view controller, giving it a chance to do something with the secondary view controller’s content. Most view controllers do nothing by default but the UINavigationControllerclass responds by pushing the secondary view controller onto its navigation stack. Read more…