The Foundation framework has a lot of string-based constants. For example, UIKit
uses NSNotifications
to publishing notifications for an iOS app's lifecycle.
NSString *const UIApplicationDidEnterBackgroundNotification NSString *const UIApplicationWillEnterForegroundNotification NSString *const UIApplicationDidFinishLaunchingNotification;
New for Foundation, Objective-C now has the ability to use strongly typed string enumerations. This new feature allowed the Foundation team to update the enumerations in Objective-C. Our notifications listed earlier can now use the NSNotificationName
type and convert our preceding constants to:
In Objective-C:
typedef NSString *NSNotificationName NS_EXTENSIBLE_STRING_ENUM; NSNotificationName const UIApplicationDidEnterBackgroundNotification NSNotificationName const UIApplicationWillEnterForegroundNotification NSNotificationName const UIApplicationDidFinishLaunchingNotification...