Protocol

NSObjectProtocol

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

Declaration

protocol NSObjectProtocol

Overview

An object that conforms to this protocol can be considered a first-class object. Such an object can be asked about its:

  • Class, and the place of its class in the inheritance hierarchy.

  • Conformance to protocols.

  • Ability to respond to a particular message.

The Cocoa root class NSObject adopts this protocol, so all objects inheriting from NSObject have the features described by this protocol.

Topics

Identifying Classes

var superclass: AnyClass?

Returns the class object for the receiver’s superclass.

Required.

Identifying and Comparing Objects

func isEqual(Any?) -> Bool

Returns a Boolean value that indicates whether the receiver and a given object are equal.

Required.

var hash: Int

Returns an integer that can be used as a table address in a hash table structure.

Required.

func `self`() -> Self

Returns the receiver.

Required.

Testing Object Inheritance, Behavior, and Conformance

func isKind(of: AnyClass) -> Bool

Returns a Boolean value that indicates whether the receiver is an instance of given class or an instance of any class that inherits from that class.

Required.

func isMember(of: AnyClass) -> Bool

Returns a Boolean value that indicates whether the receiver is an instance of a given class.

Required.

func responds(to: Selector!) -> Bool

Returns a Boolean value that indicates whether the receiver implements or inherits a method that can respond to a specified message.

Required.

func conforms(to: Protocol) -> Bool

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

Required.

Describing Objects

var description: String

Returns a string that describes the contents of the receiver.

Required.

var debugDescription: String

Returns a string that describes the contents of the receiver for presentation in the debugger.

Sending Messages

func perform(Selector!) -> Unmanaged<AnyObject>!

Sends a specified message to the receiver and returns the result of the message.

Required.

func perform(Selector!, with: Any!) -> Unmanaged<AnyObject>!

Sends a message to the receiver with an object as the argument.

Required.

func perform(Selector!, with: Any!, with: Any!) -> Unmanaged<AnyObject>!

Sends a message to the receiver with two objects as arguments.

Required.

Identifying Proxies

func isProxy() -> Bool

Returns a Boolean value that indicates whether the receiver does not descend from NSObject.

Required.

Relationships

Inherited By

Conforming Types

See Also

Object Basics

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.

NSKeyValueCoding

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

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software