Class

NSObject

The root class of most Objective-C class hierarchies, from which subclasses inherit a basic interface to the runtime system and the ability to behave as Objective-C objects.

Declaration

class NSObject

Topics

Initializing a Class

class func initialize()

Initializes the class before it receives its first message.

class func load()

Invoked whenever a class or category is added to the Objective-C runtime; implement this method to perform class-specific behavior upon loading.

Creating, Copying, and Deallocating Objects

init()

Implemented by subclasses to initialize a new object (the receiver) immediately after memory for it has been allocated.

func copy() -> Any

Returns the object returned by copy(with:).

func mutableCopy() -> Any

Returns the object returned by mutableCopy(with:) where the zone is nil.

Identifying Classes

class func superclass() -> AnyClass?

Returns the class object for the receiver’s superclass.

class func isSubclass(of: AnyClass) -> Bool

Returns a Boolean value that indicates whether the receiving class is a subclass of, or identical to, a given class.

Testing Class Functionality

class func instancesRespond(to: Selector!) -> Bool

Returns a Boolean value that indicates whether instances of the receiver are capable of responding to a given selector.

Testing Protocol Conformance

class func conforms(to: Protocol) -> Bool

Returns a Boolean value that indicates whether the receiver conforms to a given protocol.

Obtaining Information About Methods

func method(for: Selector!) -> IMP!

Locates and returns the address of the receiver’s implementation of a method so it can be called as a function.

class func instanceMethod(for: Selector!) -> IMP!

Locates and returns the address of the implementation of the instance method identified by a given selector.

Describing Objects

class func description() -> String

Returns a string that represents the contents of the receiving class.

Supporting Discardable Content

var autoContentAccessingProxy: Any

A proxy for the receiving object

Sending Messages

func perform(Selector, with: Any?, afterDelay: TimeInterval)

Invokes a method of the receiver on the current thread using the default mode after a delay.

func perform(Selector, with: Any?, afterDelay: TimeInterval, inModes: [RunLoop.Mode])

Invokes a method of the receiver on the current thread using the specified modes after a delay.

func performSelector(onMainThread: Selector, with: Any?, waitUntilDone: Bool)

Invokes a method of the receiver on the main thread using the default mode.

func performSelector(onMainThread: Selector, with: Any?, waitUntilDone: Bool, modes: [String]?)

Invokes a method of the receiver on the main thread using the specified modes.

func perform(Selector, on: Thread, with: Any?, waitUntilDone: Bool)

Invokes a method of the receiver on the specified thread using the default mode.

func perform(Selector, on: Thread, with: Any?, waitUntilDone: Bool, modes: [String]?)

Invokes a method of the receiver on the specified thread using the specified modes.

func performSelector(inBackground: Selector, with: Any?)

Invokes a method of the receiver on a new background thread.

class func cancelPreviousPerformRequests(withTarget: Any)

Cancels perform requests previously registered with the perform(_:with:afterDelay:) instance method.

Forwarding Messages

func forwardingTarget(for: Selector!) -> Any?

Returns the object to which unrecognized messages should first be directed.

Dynamically Resolving Methods

class func resolveClassMethod(Selector!) -> Bool

Dynamically provides an implementation for a given selector for a class method.

class func resolveInstanceMethod(Selector!) -> Bool

Dynamically provides an implementation for a given selector for an instance method.

Handling Errors

func doesNotRecognizeSelector(Selector!)

Handles messages the receiver doesn’t recognize.

Archiving

func awakeAfter(using: NSCoder) -> Any?

Overridden by subclasses to substitute another object in place of the object that was decoded and subsequently received this message.

var classForArchiver: AnyClass?

The class to substitute for the receiver's own class during archiving.

var classForCoder: AnyClass

Overridden by subclasses to substitute a class other than its own during coding.

var classForKeyedArchiver: AnyClass?

Subclasses to substitute a new class for instances during keyed archiving.

class func classFallbacksForKeyedArchiver() -> [String]

Overridden to return the names of classes that can be used to decode objects if their class is unavailable.

class func classForKeyedUnarchiver() -> AnyClass

Overridden by subclasses to substitute a new class during keyed unarchiving.

func replacementObject(for: NSArchiver) -> Any?

Overridden by subclasses to substitute another object for itself during archiving.

Deprecated
func replacementObject(for: NSCoder) -> Any?

Overridden by subclasses to substitute another object for itself during encoding.

func replacementObject(for: NSKeyedArchiver) -> Any?

Overridden by subclasses to substitute another object for itself during keyed archiving.

class func setVersion(Int)

Sets the receiver's version number.

class func version() -> Int

Returns the version number assigned to the class.

Working with Class Descriptions

var attributeKeys: [String]

An array of NSString objects containing the names of immutable values that instances of the receiver's class contain.

var classDescription: NSClassDescription

An object containing information about the attributes and relationships of the receiver’s class.

func inverse(forRelationshipKey: String) -> String?

For a given key that defines the name of the relationship from the receiver’s class to another class, returns the name of the relationship from the other class to the receiver’s class.

var toManyRelationshipKeys: [String]

An array containing the keys for the to-many relationship properties of the receiver.

var toOneRelationshipKeys: [String]

The keys for the to-one relationship properties of the receiver, if any.

Improving Accessibility

UIAccessibility

A set of methods that provide accessibility information about views and controls in an app's user interface.

UIAccessibilityContainer

Provide a set of methods that view subclasses use to make subcomponents accessible as separate elements.

UIAccessibilityAction

A set of methods that accessibility elements can use to support specific actions.

UIAccessibilityFocus

An informal protocol that provides a way to find out whether an assistive technology, such as VoiceOver, is focused on an accessible element.

UIAccessibilityDragging

A pair of properties to allow you to fine-tune how drags and drops are exposed to assistive technologies.

Scripting

var classCode: FourCharCode

The receiver's Apple event type code, as stored in the NSScriptClassDescription object for the object’s class.

var className: String

A string containing the name of the class.

func copyScriptingValue(Any, forKey: String, withProperties: [String : Any]) -> Any?

Creates and returns one or more scripting objects to be inserted into the specified relationship by copying the passed-in value and setting the properties in the copied object or objects.

func newScriptingObject(of: AnyClass, forValueForKey: String, withContentsValue: Any?, properties: [String : Any]) -> Any?

Creates and returns an instance of a scriptable class, setting its contents and properties, for insertion into the relationship identified by the key.

var scriptingProperties: [String : Any]?

An NSString-keyed dictionary of the receiver's scriptable properties.

func scriptingValue(for: NSScriptObjectSpecifier) -> Any?

Given an object specifier, returns the specified object or objects in the receiving container.

Integrating with Combine

struct NSObject.KeyValueObservingPublisher

A Combine publisher that produces a new element whenever the observed value changes.

Key-Value Observing

NSKeyValueObserving

An informal protocol that objects adopt to be notified of changes to the specified properties of other objects.

Key-Value Coding

NSKeyValueBindingCreation

A set of methods that you can use to create and remove bindings between view objects and controllers, or between controllers and model objects.

NSKeyValueCoding

A mechanism by which you can access the properties of an object indirectly by name or key.

NSScriptKeyValueCoding

A collection of methods that provide additional capabilities for working with key-value coding.

NSScriptKeyValueCoding Exception Names

Exceptions raised by key-value coding methods.

Interacting with Web Plug-ins

WebPlugInContainer

WebPlugInContainer is an informal protocol that enables a plug-in to send messages to the application.

WebPlugIn

The WebPlugIn informal protocol defines methods that enable interaction between an application using the WebKit framework and any WebKit-based plug-ins it may use.

Implementing Web Scripting

WebScripting

WebScripting is an informal protocol that defines methods that classes can implement to export their interfaces to a WebScript environment such as JavaScript.

Supporting Cocoa Scripting

NSScriptingComparisonMethods

A collection of methods useful for comparing script objects.

Deprecated

Avoid using deprecated classes and protocols in your apps.

Deprecated Symbols

Review symbols that are no longer supported and find the replacements to use instead.

Instance Properties

Type Properties

class var accessInstanceVariablesDirectly: Bool

Returns a Boolean value that indicates whether the key-value coding methods should access the corresponding instance variable directly on finding no accessor method for a property.

Instance Methods

func actionProperty() -> String!

Sent to the delegate to request the property the action applies to.

func attemptRecovery(fromError: Error, optionIndex: Int) -> Bool

Implemented to attempt a recovery from an error noted in an application-modal dialog.

func authorizationViewCreatedAuthorization(SFAuthorizationView!)

Sent to the delegate to indicate the authorization object has been created or changed. If you have saved a copy of the authorization object for your own purposes, you should discard it and call authorization for a new authorization object.

func authorizationViewDidAuthorize(SFAuthorizationView!)

Sent to the delegate to indicate the user was authorized and the authorization view was changed to unlocked.

func authorizationViewDidDeauthorize(SFAuthorizationView!)

Sent to the delegate to indicate the user was deauthorized and the authorization view was changed to locked.

func authorizationViewDidHide(SFAuthorizationView!)

Sent to the delegate to indicate that the view’s visibility has changed.

func authorizationViewReleasedAuthorization(SFAuthorizationView!)

Sent to the delegate to indicate that deauthorization is about to occur.

func authorizationViewShouldDeauthorize(SFAuthorizationView!) -> Int8

Sent to the delegate when a user clicks the open lock icon.

func awakeFromNib()

Prepares the receiver for service after it has been loaded from an Interface Builder archive, or nib file.

func candidates(Any!) -> [Any]!

Returns an array of candidates.

func certificatePanelShowHelp(SFCertificatePanel!) -> Int8

Implements custom help behavior for the modal panel.

func chooseIdentityPanelShowHelp(SFChooseIdentityPanel!) -> Int8

Implements custom help behavior for the modal panel.

func commitComposition(Any!)

Informs the controller that the composition should be committed.

func composedString(Any!) -> Any!

Return the current composed string.

func compositionParameterView(QCCompositionParameterView!, didChangeParameterWithKey: String!)

Called after an input parameter in the composition parameter view has been edited.

func compositionParameterView(QCCompositionParameterView!, shouldDisplayParameterWithKey: String!, attributes: [AnyHashable : Any]!) -> Bool

Allows you to define which composition parameters are visible in the user interface when the composition parameter view refreshes.

func compositionPickerView(QCCompositionPickerView!, didSelect: QCComposition!)

Performs custom tasks when the selected composition in the composition picker view changes.

func compositionPickerViewDidStartAnimating(QCCompositionPickerView!)

Performs custom tasks when the composition picker view starts animating a composition.

func compositionPickerViewWillStopAnimating(QCCompositionPickerView!)

Performs custom tasks when the composition picker view stops animating a composition.

func didCommand(by: Selector!, client: Any!) -> Bool

Processes a command generated by user action such as typing certain keys or pressing the mouse button.

func doesContain(Any) -> Bool

Returns a Boolean value that indicates whether the receiver contains a given object.

func exceptionHandler(NSExceptionHandler!, shouldHandle: NSException!, mask: Int) -> Bool

Implemented by the delegate to evaluate whether the delegating NSExceptionHandler instance should handle a given exception.

func exceptionHandler(NSExceptionHandler!, shouldLogException: NSException!, mask: Int) -> Bool

Implemented by the delegate to evaluate whether the delegating NSExceptionHandler instance should log a given exception.

func handle(NSEvent!, client: Any!) -> Bool

Handles key down and mouse events.

func imageBrowser(IKImageBrowserView!, backgroundWasRightClickedWith: NSEvent!)

Performs custom tasks when the user right-clicks the image browser view background.

func imageBrowser(IKImageBrowserView!, cellWasDoubleClickedAt: Int)

Performs custom tasks when the user double-clicks an item in the image browser view.

func imageBrowser(IKImageBrowserView!, cellWasRightClickedAt: Int, with: NSEvent!)

Performs custom tasks when the user right-clicks an item in the image browser view.

func imageBrowser(IKImageBrowserView!, itemAt: Int) -> Any!

Returns an object for the item in an image browser view that corresponds to the specified index.

func imageBrowser(IKImageBrowserView!, moveItemsAt: IndexSet!, to: Int) -> Bool

Signals that the specified items should be moved to the specified destination.

func imageBrowser(IKImageBrowserView!, removeItemsAt: IndexSet!)

Signals that a remove operation should be applied to the specified items.

func imageBrowserSelectionDidChange(IKImageBrowserView!)

Performs custom tasks when the selection changes.

func imageRepresentation() -> Any!

Returns the image to display.

func imageRepresentationType() -> String!

Returns the representation type of the image to display.

func imageSubtitle() -> String!

Returns the display subtitle of the image.

func imageTitle() -> String!

Returns the display title of the image.

func imageUID() -> String!

Returns a unique string that identifies the data source item.

func imageVersion() -> Int

Returns the version of the item.

func inputText(String!, client: Any!) -> Bool

Handles key down events that do not map to an action method.

func inputText(String!, key: Int, modifiers: Int, client: Any!) -> Bool

Receives Unicode, the key code that generated it, and any modifier flags.

func isCaseInsensitiveLike(String) -> Bool

Returns a Boolean value that indicates whether receiver is considered to be “like” a given string when the case of characters in the receiver is ignored.

func isEqual(to: Any?) -> Bool

Returns a Boolean value that indicates whether the receiver is equal to another given object.

func isGreaterThan(Any?) -> Bool

Returns a Boolean value that indicates whether the receiver is greater than another given object.

func isGreaterThanOrEqual(to: Any?) -> Bool

Returns a Boolean value that indicates whether the receiver is greater than or equal to another given object.

func isLessThan(Any?) -> Bool

Returns a Boolean value that indicates whether the receiver is less than another given object.

func isLessThanOrEqual(to: Any?) -> Bool

Returns a Boolean value that indicates whether the receiver is less than or equal to another given object.

func isLike(String) -> Bool

Returns a Boolean value that indicates whether the receiver is "like" another given object.

func isNotEqual(to: Any?) -> Bool

Returns a Boolean value that indicates whether the receiver is not equal to another given object.

func numberOfGroups(inImageBrowser: IKImageBrowserView!) -> Int

Returns the number of groups in an image browser view.

func numberOfItems(inImageBrowser: IKImageBrowserView!) -> Int

Returns the number of records managed by the data source object.

func originalString(Any!) -> NSAttributedString!

Return the string that consists of the precomposed Unicode characters.

func performAction(for: ABPerson!, identifier: String!)

Sent to the delegate to perform the action.

func prepareForInterfaceBuilder()

Called when a designable object is created in Interface Builder.

func saveOptions(IKSaveOptions!, shouldShowUTType: String!) -> Bool

Called to determine if the specified uniform type identifier should be shown in the save panel.

func shouldEnableAction(for: ABPerson!, identifier: String!) -> Bool

Sent to the delegate to determine whether the action should be enabled.

func title(for: ABPerson!, identifier: String!) -> String!

Sent to the delegate to request the title of the menu item for the action.

See Also

Object Basics

protocol NSObjectProtocol

The group of methods that are fundamental to all Objective-C objects.

NSKeyValueCoding

A mechanism by which you can access the properties of an object indirectly by name or key.