Object is the superclass of all classes. Methods implemented here are inherited by all Objective C classes.
+ initializeEvery class in the application, receives an initialize message when the program starts. By default this method doesn't do anything. It can be overridden to do class initialization.
Note that all classes are guarantueed to receive initialize, before any other message is sent. Other runtimes differ with ours in this respect, that initialize is sometimes sent to a class, just before an instance of that particular class is being used (as opposed to all classes receiving initialize, before any instance receives a message).
Note: In some runtimes, the equivalent functionality is called +load instead of +initialize.
On systems that allow to recover from a failed memory allocation call, new might raise an exception that can be handled with ifOutOfMemory:. The default handler for this exception aborts the process.
When compiling with the -gc option, the memory for the instance is not being freed. The garbage collector takes cares of this.
Note: For portability, this method always needs to be used as follows:
Note: This method is Portable Object Compiler only.
See also: +class, +superclass, +inheritsFrom:
When performing a poseAs:, the following rules must be followed:
Implementation details:
The same restrictions apply as for poseAs: : the subclass needs to be a direct subclass of superClass and it may not add instance variables. However, unlike poseAs:, the subclass will not be substituted for the superClass for purposes as fileIn: etc. Also, (unlike poseAs:) when the subclass adds a method to the superClass that was overridden from the superClass, then this method will not replace the method of the superClass.
Note: Portable Object Compiler only.
Note: Portable Object Compiler only.
If the subclass does not implement the method, then this implementation is inherited. It generates an error message.
When designing a class, the method notImplemented: can be used to implement stubs for the methods that make up the class. When the design phase is finished, the actual implementation can begin. If later, by accident, not all functionality is properly implemented, the method notImplemented: will help finding this.
An abstract superclass, called MyClass for example, can use this method to indicate that subclasses should not send (or be sent) a new message, but that they are supposed to send some other method (such as foo: perhaps) :
See also: doesNotUnderstand:
This method is present in most runtimes, but it was reimplemented in the Portable Object Compiler, so that the error can be caugh, using the Block instance method ifError:. Traditionally, the method error: simply aborts the process, and the default error handler in our implementation does the same thing.
The halt method pops an error handler from the stack of handlers, as maintained by ifError:. The handler is evaluated with the message and the receiver of the halt: message, as arguments. If the handler returns, it is pushed again on the stack. If there were no handlers on the stack, the default error handler is used instead, as returned by errorHandler.
Note: Portable Object Compiler specific
Use of this method is not encouraged, because by using the resulting function pointer, one is bypassing (the benefits of) dynamic binding.
Use of this method is not encouraged, because by using the resulting function pointer, one is bypassing (the benefits of) dynamic binding.
This method is extremely useful for debugging. The compiler automatically implements Filer methods, so this method dumps instance variables of the object in a symbolic format, without the programmer having to implement debug/printing routines.
Method for Stepstone compatibility. Used in Producer code.
This is the method to override in subclasses to make print, printLine etc. to work.
This message can be sent to any factory object without regard of the class of the object being read in. In other words, if file foo contains a saved instance of a OrdCltn, then
This method will be invoked twice by the Filer class, during archiving.
One should realize that, at the time this method is invoked, not all objects are guarantueed to be in a usable state. This is only true once the filer starts sending awakeFrom: messages.
new
+ new
Factory method to create and return a new instance of the class. The default implementation clears (zeroes) the memory for instance variables and initializes the isa pointer.
copy
- copy
Should return a copy of the object. The difference with deepCopy is, that this copy might share pointers etc. with the receiver of the message. By default, copy just makes a byte copy of the memory for instance variables.
deepCopy
- deepCopy
Should return a deep copy of the object. Usually this means a copy that doesn't share objects with the original object and that can be free'ed independently. By default, deepCopy just makes a byte copy of the memory for instance variables.
free
- free
Sets the isa pointer for this instance to nil, frees the memory for the instance, and returns nil.
self
- self
Method that does nothing, except for returning self.
yourself
- yourself
Method that does nothing, except for returning self.
class
- class
Returns the class object for the receiver's class.
superclass
- superclass
Returns the superclass object for the receiver's class. For GNU compatibility.
superClass
- superClass
Same as superclass. For Stepstone compatibility.
class
+ class
Traditionally, the class of a class does NOT return the metaclass, but rather self (that, it, the class itself).
superclass
+ superclass
For GNU compatibility. Returns the superclass of this factory (which is another factory object), or nil for the root.
superClass
+ superClass
Same as superclass, but for Stepstone compatibility. Returns the superclass of this factory (which is another factory object), or nil for the root.
name
- (STR) name
Returns the name of the object; implemented by default to return the name of the object's class.
name
+ (STR) name
Returns the name of the class.
findClass:
- findClass :(STR) aClassName
Returns the id of aClassName, if that class has been linked in this executable image, else nil.
selOfSTR:
- (SEL) selOfSTR :(STR) aSelName
Returns the selector of the string aSelName. Raises an exception if not found.
idOfSTR:
- idOfSTR :(STR) aClassName
Returns the id of the class named aClassName. Differs from findClass: in that an exception will be raised if aClassName is not found
hash
- (unsigned) hash
Returns a small integer value derived from the object, that should be equal for two objects for which isEqual: returns YES. By default, returns the pointer address of the object as an unsigned integer.
isEqual:
- (BOOL) isEqual : anObject
Should return YES if the receiver is equal to anObject. By default, compares the pointer addresses of the two objects.
isEqual:
+ (BOOL) isEqual : anObject
Tests whether two class objects are the same.
isSame:
- (BOOL) isSame : anObject
Returns YES if the pointer addresses of the two objects are equal.
notEqual:
- (BOOL) notEqual : anObject
Whether isEqual: returns NO.
notSame:
- (BOOL) notSame : anObject
Whether isSame: returns NO.
compare:
- (int) compare : anObject
Should return an integer which is less than, equal to, or greater than zero, if the receiver is less than, equal to, or greater than anObject. The return value is called the method's comparison value.
respondsTo:
- (BOOL) respondsTo :(SEL) aSelector
Test whether the class implements a certain method. Returns YES if the class itself, or one of its superclasses, implements the method, otherwise NO. The method does not generate an error if the class does not implement the method.
isMemberOf:
- (BOOL) isMemberOf : aClass
Returns YES if the receiver is an instance of aClass, but NO if it's an instance of some subclass of aClass.
isKindOf:
- (BOOL) isKindOf : aClass
Returns YES if the receiver is an instance of aClass or an instance from some subclass of aClass.
The reason is that some compilers do not allow class names as expressions, so the class must be obtained by sending a class message. In addition, some compilers have a isKindOf: method that takes an id argument, but the return value of self or class can be SHR for those compilers. Therefore, it's necessary to cast the return value to id (to avoid compiler warnings).
[ foo isKindOf:(id) [Classname class] ];
subclasses
+ subclasses
Returns a OrdCltn of direct subclasses of the class that receives the message. If the class has no subclasses, then this method returns an empty OrdCltn (not nil). The class itself is not considered subclass of itself.
poseAs:
+ poseAs : superClass
The poseAs: method permits to modify a supplied superClass (for which, for example, no source code is available) by substituting a direct subclass of superClass. It is normally used inside +initialize, but the Portable Object Compiler allows poseAs: to be used anywhere in the program.
The example shows how the initialize of some subclass, called for example SubSet, can substitute SubSet for Set. Methods defined in SubSet override those defined in the superclass, and new methods from SubSet, will appear to have come from the Set class.
+ initialize { [self poseAs:[Set self]]; return self; }
The Portable Object Compiler implementation of poseAs: differs from some other runtimes, since it allows poseAs: to happen, even after messages have been sent to instances of posing or impersonated class.
Note: All Objective-C compilers provide this functionality (sometimes with restrictions on when the method can be called)
addMethodsTo:
+ addMethodsTo : superClass
The addMethodsTo: method permits to modify a supplied superClass (for which, for example, no source code is available) by adding the (instance and factory) methods of a direct subclass, to superClass. It is normally used inside +initialize, but the Portable Object Compiler allows addMethodsTo: to be used anywhere in the program.
Note: Portable Object Compiler only.
subclass:
+ subclass :(STR) name
Method to dynamically subclass a class. Returns a new class object, registered under the name name, as subclass of self. Methods like findClass: will also return this new class.
inheritsFrom:
+ (BOOL) inheritsFrom : aClass
Whether the receiving class is a subclass (direct or not) from aClass.
subclassResponsibility:
- subclassResponsibility :(SEL) aSelector
Used in classes to indicate that the functionality is assumed to be implemented by a subclass, as in:
The variable _cmd is just as self an implicit argument of every method; in this case, it is the selector of the method that should be implemented by a subclass.
- foo { [self subclassResponsibility:_cmd]; }
subclassResponsibility
- subclassResponsibility
For Stepstone compatibility.
notImplemented:
- notImplemented :(SEL) aSelector
Method to indicate that a method (indentified by aSelector) is temporarily not implemented :
The variable _cmd is, just like self, an implicit argument of every method; in this case, it is the selector of the method foo.
-foo { [self notImplemented:_cmd]; }
notImplemented
- notImplemented
For Stepstone compatibility.
shouldNotImplement:
- shouldNotImplement :(SEL) aSelector
This is the opposite of subclassResponsibility and a stronger form of notImplemented: : shouldNotImplement: should be used, when the class is not supposed to implement some method, i.e. when the method is not appropriate for the class and its subclasses.
This announces that new, which would otherwise have been inherited from the root class, is not an appropriate way to create an instance of a subclass of MyClass.
+new { [self shouldNotImplement:_cmd]; }
+foo:aBar { self = [super new];bar = aBar; return self; }
shouldNotImplement
- shouldNotImplement
Method for Stepstone compatibility.
shouldNotImplement:from:
- shouldNotImplement :(SEL) aSelector from : superClass
Method for Stepstone compatibility.
doesNotRecognize:
- doesNotRecognize :(SEL) aSelector
Automatically sent by the runtime when the class does not implement aSelector.
doesNotUnderstand:
- doesNotUnderstand :(SEL) aSelector
For compatibility with Smalltalk. Implemented in terms of doesNotRecognize:. You have to override doesNotRecognize:, not this method.
error:
- error :(STR) format,...
Generate an error message. Takes a format string in the style of the C library function printf, with a variable number of arguments. Returns self.
halt:
- halt : message
This method is equivalent to the error: method but takes an object as argument.
methodFor:
- (IMP) methodFor :(SEL) aSelector
Returns a function implementation pointer for aSelector. Returns a pointer to an error handling function if the object does not respond to aSelector.
instanceMethodFor:
+ (IMP) instanceMethodFor :(SEL) aSelector
Returns a function implementation pointer for aSelector. Returns a pointer to an error handling function if the object does not respond to aSelector.
perform:
- perform :(SEL) aSelector
Returns the value that would result when sending aSelector to the receiver.
perform:with:
- perform :(SEL) aSelector with : anObject
Returns the value that would result when sending aSelector to the receiver with a single argument anObject. The following are equivalent :
and
[aReceiver perform:@selector(do:) with:anObject];
[aReceiver do:anObject];
perform:with:with:
- perform :(SEL) aSelector with : anObject with : otherObject
Returns the value that would result when sending aSelector to the receiver with arguments anObject and otherObject.
perform:with:with:with:
- perform :(SEL) aSelector with : anObject with : otherObject with : thirdObj
Returns the value that would result when sending aSelector to the receiver with arguments anObject and otherObject.
print
- print
Prints the object to the stdout and returns self. Implemented as,
meaning that if you implement printOn:, then this method will work.
return [self printOn:stdout];
print
+ print
Factory method to print the name of the class to the stdout and to return self.
printLine
- printLine
Prints the object (in the sense of print) and then a newline.
show
- show
Displays the object on the stderr, by using Filer code, and returns self. Because it is implemented in terms of Filer code, this method is completely unrelated to the print method, although that the goal in both cases is to print a symbolic representation of the object.
printOn:
- printOn :(IOD) anIOD
Should print the object to anIOD, which is of type IOD (defined as an input output device, a FILE pointer, to be used with standard I/O). Should return the receiver. By default, the method prints nothing.
objcrtRevision
+ (STR) objcrtRevision
Returns the version string of the runtime being used.
readFrom:
+ readFrom :(STR) aFileName
Activates the object stored in the file aFileName. The object will in all respects be functional, as it was before being stored. Works by indirectly calling fileIn(). The class AsciiFiler must be linked into the application for this method to work.
will work, ie. the receiver doesn't need to be OrdCltn. Returns nil on failure.
id myCollection = [Object readFrom:"foo"];
storeOn:
- (BOOL) storeOn :(STR) aFileName
Stores the receiver to a file named aFileName, in a format such that the object can then be activated later, using the readFrom: method. Works by indirectly calling the function storeOn(). The class AsciiFiler must be linked into the application for this method to work
fileOutOn:
- fileOutOn : aFiler
Writes the receiver on aFiler. This is the method that a subclass will override to do it own processing, if the default implementation, which automatically writes out all instance variables of type id, does not suffice.
fileInFrom:
+ fileInFrom : aFiler
Creates a new instance of the class, files in the instance from aFiler (by sending the new object a fileInFrom:) message, and returns the new object.
fileInFrom:
- fileInFrom : aFiler
Reads the receiver from aFiler. The default implementation automatically reads in instance variables of type id. This method must be overridden to match fileOutFor:, if that method was implemented by the subclass.