Return to the Main Index
Return to the Alphabetic Index

Copyright (c) 1994 by NeXT Computer, Inc. All Rights Reserved.

NSObject

Adopted By: NSObject

NSProxy

Declared In: Foundation/NSObject.h

Protocol Description

The NSObject protocol declares methods that all objectsno matter which root class they descend from (NSObject, NSProxy, or another root class)should implement to work well within OpenStep. Some of the methods in this protocol reveal an object's primary attributes: its position in the class hierarchy, its conformance to other protocols, and whether it responds to specific messages. Others let it be manipulated in various ways. For example, it can be asked to perform methods that are determined at runtime (using the perform:... methods) or to participate in OpenStep's automatic deallocation scheme (using the retain, release, and autorelease methods).

By conforming to this protocol an object advertises that it has the basic behaviors necessary to work with the OpenStep's container classes (such as NSArray or NSDictionary).

Identifying and Comparing Instances

- (unsigned int)hash Returns an unsigned integer that can be used as a table address in a hash table structure. Two objects that are equal must hash to the same value.

- (BOOL)isEqual:(id)anObject Returns YES if the receiver and anObject have equal values; otherwise returns NO.

- (id)self Returns the receiver.

Identifying Class and Superclass

- (Class)class Returns the class object for the receiver's class.

- (Class)superclass Returns the class object for the receiver's superclass.

Determining Allocation Zones

- (NSZone *)zone Returns a pointer to the zone from which the receiver was allocated.

Sending Messages Determined at Run Time

- (id)perform:(SEL)aSelector Sends an aSelector message to the receiver and returns the result of the message. If aSelector is null, an NSInvalidArgumentException is raised.

- (id)perform:(SEL)aSelector Sends an aSelector message to the receiver with anObject

withObject:(id)anObject as an argument. If aSelector is null, an NSInvalidArgumentException is raised.

- (id)perform:(SEL)aSelector Sends the receiver an aSelector message with anObject and

withObject:(id)anObject anotherObject as arguments. If aSelector is null, an

withObject:(id)anotherObject NSInvalidArgumentException is raised.

Identifying Proxies

- (BOOL)isProxy Returns YES to indicate that the receiver is an NSProxy, rather than an object that descends from NSObject. Otherwise, it returns NO.

Testing Inheritance Relationships

- (BOOL)isKindOfClass:(Class)aClass Returns YES if the receiver is an instance of aClass or an instance of any class that inherits from aClass. Otherwise, it returns NO.

- (BOOL)isMemberOfClass:(Class)aClass Returns YES if the receiver is an instance of aClass. Otherwise, it returns NO.

Testing for Protocol Conformance

- (BOOL)conformsToProtocol:(Protocol *)aProtocol

Returns YES if the class of the receiver conforms to aProtocol, and NO if it doesn't.

Testing Class Functionality

- (BOOL)respondsToSelector:(SEL)aSelector Returns YES if the receiver implements or inherits a method that can respond to aSelector messages, and NO if it doesn't.

Managing Reference Counts

- (id)autorelease As defined in the NSObject class, decrements the receiver's reference count. When the count reaches 0, adds the object to the current autorelease pool. Returns self. Objects in the pool are released later, typically at the top of the event loop.

- (oneway void)release As defined in the NSObject class, decrements the receiver's reference count. When the count reaches 0, the object is automatically deallocated immediately.

- (id)retain As defined in the NSObject class, retain increments the receiver's reference count. You send an object a retain message when you want to prevent it from being deallocated without your express permission. Returns self as a convenience.

- (unsigned int)retainCount Returns the receiver's reference count for debugging purposes.

Describing the Object

- (NSString *)description Returns a human-readable description of the receiver.