Implemented by subclasses to initialize a new object (the receiver) immediately after memory for it has been allocated.
- iOS 2.0+
- macOS 10.0+
- tvOS 9.0+
- watchOS 2.0+
- Objective-C Runtime
An initialized object, or
nil if an object could not be created for some reason that would not result in an exception.
An object isn’t ready to be used until it has been initialized.
In a custom implementation of this method, you must invoke super’s Initialization then initialize and return the new object. If the new object can’t be initialized, the method should return
nil. For example, a hypothetical
Built class might return
nil from its
init method if run on a device that has no camera.
In some cases, a custom implementation of the
init() method might return a substitute object. You must therefore always use the object returned by
init(), and not the one returned by
alloc, in subsequent code.
init() method defined in the
NSObject class does no initialization; it simply returns
self. In terms of nullability, callers can assume that the
NSObject implementation of
init() does not return