MOAbstractClassError |
#define MOAbstractClassError( _class_) \ do { \ Class cls = [_class_ class]; \ MOAssert( ( [self class] != cls), @"Error. Attempt to instantiate abstract class %@.", NSStringFromClass( cls)); \ } while( 0)
This macro causes an assertion failure if self is an instance of class. It is used to indicate that someone is trying to instantiate an abstract class. Usually it is called from an override of +allocWithZone: after the override has determined that the class being allocated is abstract. The macro takes one argument:
_class_: The abstract class. Generally this is the class whose implementation is invoking the macro.
MOAssert |
#define MOAssert( _condition_, _desc_, _args_...) \ do { \ if ( !( _condition_)) { \ MOHandleAssertionFailure( YES, _cmd, self, __PRETTY_FUNCTION__, __FILE__, __LINE__, ( _desc_), ## _args_); \ } \ } while( 0)
It is the primitive assertion macro. All the other assertion macros wind up invoking this macro one or more times. If MO_BLOCK_ASSERTS is defined, this macro does nothing, otherwise if _condition_ is false it calls MOHandleAssertionFailure(). The macro takes a variable number of arguments:
_condition_: The conditional expression being asserted. This can be any expression that is legal within the parens of an if () statement.
_desc_: The description or format string for the assertion. Any additional arguments (_args_) are replacement arguments for % directives in the format string.
MOAssertClass |
#define MOAssertClass( _object_, _class_) \ do { \ Class cls = [_class_ class]; \ id obj = ( _object_); \ MOAssert( ( obj != nil), @"%s should be an object of class %@, but it is nil.", #_object_, NSStringFromClass( cls)); \ MOAssert( ( [obj isKindOfClass:cls]), @"%s should be an object of class %@, but it is of class %@.", #_object_, NSStringFromClass( cls), NSStringFromClass( [obj class])); \ } while( 0)
This macro makes two assertions: first that _object_ is not nil, and second that [_object_ isKindOfClass:_class_]. The macro takes two arguments:
_object_: The _object being tested.
_class_: The class that the object is required to be a kind of.
MOAssertClassOrNil |
#define MOAssertClassOrNil( _object_, _class_) \ do { \ Class cls = [_class_ class]; \ id obj = ( _object_); \ MOAssert( ( obj == nil || [obj isKindOfClass:cls]), @"%s should be an object of class %@, but it is of class %@.", #_object_, NSStringFromClass( cls), NSStringFromClass( [obj class])); \ } while( 0)
This macro asserts that _object_ is either nil or that [_object_ isKindOfClass:_class_]. The macro takes two arguments:
_object_: The _object being tested.
_class_: The class that the object is required to be a kind of.
MOAssertNonEmptyString |
#define MOAssertNonEmptyString( _object_) \ do { \ Class cls = [NSString class]; \ id obj = ( _object_); \ MOAssert( ( obj != nil), @"%s should be a non-empty NSString, but it is nil.", #_object_); \ MOAssert( ( [obj isKindOfClass:cls]), @"%s should be a non-empty NSString, but it is of class %@.", #_object_, NSStringFromClass( [obj class])); \ MOAssert( ( ![obj isEqualToString:@""]), @"%s should be a non-empty NSString, but it is empty.", #_object_); \ } while( 0)
This macro makes three assertions: first that _object_ is not nil, second that [_object_ isKindOfClass:[NSString class]], and finally that _object_ is not equal to the empty string. The macro takes one argument:
_object_: The _object being tested.
MOAssertNonEmptyStringOrNil |
#define MOAssertNonEmptyStringOrNil( _object_) \ do { \ Class cls = [NSString class]; \ id obj = ( _object_); \ MOAssert( ( obj == nil || [obj isKindOfClass:cls]), @"%s should be a non-empty NSString, but it is of class %@.", #_object_, NSStringFromClass( [obj class])); \ MOAssert( ( obj == nil || ![obj isEqualToString:@""]), @"%s should be a non-empty NSString, but it is empty.", #_object_); \ } while( 0)
This macro makes two assertions: first that _object_ is either nil or [_object_ isKindOfClass:[NSString class]], and second that _object_ is not equal to the empty string (if it is non-nil). The macro takes one argument:
_object_: The _object being tested.
MOAssertProtocol |
#define MOAssertProtocol( _object_, _protocol_) \ do { \ Protocol *proto = ( _protocol_); \ id obj = ( _object_); \ MOAssert( ( obj != nil), @"%s should be an object conforming to %s, but it is nil.", #_object_, #_protocol_); \ MOAssert( ( [obj conformsToProtocol:proto]), @"%s should be an object conforming to %s, but it does not.", #_object_, #_protocol_); \ } while( 0)
This macro makes two assertions: first that _object_ is not nil, and second that [_object_ conformsToProtocol:_protocol_]. The macro takes two arguments:
_object_: The object being tested.
_protocol_: The protocol it is being asserted to conform to.
MOAssertProtocolOrNil |
#define MOAssertProtocolOrNil( _object_, _protocol_) \ do { \ Protocol *proto = ( _protocol_); \ id obj = ( _object_); \ MOAssert( ( obj == nil || [obj conformsToProtocol:proto]), @"%s should be an object conforming to %s, but it does not.", #_object_, #_protocol_); \ } while( 0)
This macro asserts that _object_ is either nil or that [_object_ conformsToProtocol:_protocol_]. The macro takes two arguments:
_object_: The object being tested.
_protocol_: The protocol it is being asserted to conform to.
MOAssertRespondsToSelector |
#define MOAssertRespondsToSelector( _object_, _selector_) \ do { \ SEL sel = _selector_; \ id obj = ( _object_); \ MOAssert( ( obj != nil), @"%s should be an object responding to %@, but it is nil.", #_object_, NSStringFromSelector( sel)); \ MOAssert( ( [obj respondsToSelector:sel]), @"%s should be an object responding to %@, but it does not.", #_object_, NSStringFromSelector( sel)); \ } while( 0)
This macro makes two assertions: first that _object_ is not nil, and second that [_object_ respondsToSelector:_selector_]. The macro takes two arguments:
_object_: The object being tested.
_selector_: The selector it is being asserted to implement.
MOAssertRespondsToSelectorOrNil |
#define MOAssertRespondsToSelectorOrNil( _object_, _selector_) \ do { \ SEL sel = _selector_; \ id obj = ( _object_); \ MOAssert( ( obj == nil || [obj respondsToSelector:sel]), @"%s should be an object responding to %@, but it does not.", #_object_, NSStringFromSelector( sel)); \ } while( 0)
This macro asserts that _object_ is either nil or that [_object_ respondsToSelector:_selector_]. The macro takes two arguments:
_object_: The object being tested.
_selector_: The selector it is being asserted to implement.
MOAssertString |
#define MOAssertString( _object_) \ do { \ Class cls = [NSString class]; \ id obj = ( _object_); \ MOAssert( ( obj != nil), @"%s should be an NSString, but it is nil.", #_object_); \ MOAssert( ( [obj isKindOfClass:cls]), @"%s should be an NSString, but it is of class %@.", #_object_, NSStringFromClass( [obj class])); \ } while( 0)
This macro makes two assertions: first that _object_ is not nil, and second that [_object_ isKindOfClass:[NSString class]]. The macro takes one argument:
_object_: The _object being tested.
MOAssertStringOrNil |
#define MOAssertStringOrNil( _object_) \ do { \ Class cls = [NSString class]; \ id obj = ( _object_); \ MOAssert( ( obj == nil || [obj isKindOfClass:cls]), @"%s should be an NSString, but it is of class %@.", #_object_, NSStringFromClass( [obj class])); \ } while( 0)
This macro asserts that _object_ is either nil, or that [_object_ isKindOfClass:[NSString class]]. The macro takes one argument:
_object_: The _object being tested.
MOError |
#define MOError( _desc_, _args_...) \ do { \ MOHandleAssertionFailure( YES, _cmd, self, __PRETTY_FUNCTION__, __FILE__, __LINE__, ( _desc_), ## _args_); \ } while( 0)
This macro always causes an assertion failure. It takes a format string and printf-style arguments for the format string. The macro takes a variable number of arguments:
_desc_: The description or format string for the assertion. Any additional arguments (_args_) are replacement arguments for % directives in the format string.
MOInvariantAssert |
#define MOInvariantAssert( _condition_) \ MOAssert( ( _condition_), @"Invariant broken: %s", #_condition_)
This macro simply asserts the given _condition_ with a description that indicates that failure implies a broken invariant. The condition itself is included in the message. The macro takes one argument:
_condition_: The conditional expression being asserted. This can be any expression that is legal within the parens of an if () statement.
MOParameterAssert |
#define MOParameterAssert( _condition_) \ MOAssert( ( _condition_), @"Invalid parameter not satisfying: %s", #_condition_)
This macro simply asserts the given _condition_ with a description that indicates that failure implies a bad parameter being passed to a function or method. The condition itself is included in the message. The macro takes one argument:
_condition_: The conditional expression being asserted. This can be any expression that is legal within the parens of an if () statement.
MOPostconditionAssert |
#define MOPostconditionAssert( _condition_) \ MOAssert( ( _condition_), @"Postcondition broken: %s", #_condition_)
This macro simply asserts the given _condition_ with a description that indicates that failure implies a broken postcondition. The condition itself is included in the message. The macro takes one argument:
_condition_: The conditional expression being asserted. This can be any expression that is legal within the parens of an if () statement.
MOPreconditionAssert |
#define MOPreconditionAssert( _condition_) \ MOAssert( ( _condition_), @"Precondition broken: %s", #_condition_)
This macro simply asserts the given _condition_ with a description that indicates that failure implies a broken precondition. The condition itself is included in the message. The macro takes one argument:
_condition_: The conditional expression being asserted. This can be any expression that is legal within the parens of an if () statement.
MOSubclassResponsibilityError |
#define MOSubclassResponsibilityError( _class_) \ do { \ Class cls = [_class_ class]; \ MOAssert( 0,@"Error. The method %@ must be overridden by subclasses of % @.", NSStringFromSelector( _cmd), NSStringFromClass( cls)); \ } while( 0)
This macro always causes an assertion failure. It is used to indicate that subclass responsibility that has not been fulfilled. Usually it is called from an abstract class' implementation of a method that must be overridden by all subclasses. The macro takes one argument:
_class_: The abstract class. Generally this is the class whose implementation is invoking the macro.
MOSubclassResponsibilityError |
#define MOWarning( _desc_, _args_...) \ do { \ MOHandleAssertionFailure( YES, _cmd, self, __PRETTY_FUNCTION__, __FILE__, __LINE__, ( _desc_), ## _args_); \ } while( 0)
This macro never causes an assertion failure. It simply logs an error message. The macro takes a variable number of arguments:
_desc_: The description or format string for the assertion. Any additional arguments (_args_) are replacement arguments for % directives in the format string.
MOWarning |
#define MOWarning( _desc_, _args_...) \ do { \ MOHandleAssertionFailure( YES, _cmd, self, __PRETTY_FUNCTION__, __FILE__, __LINE__, ( _desc_), ## _args_); \ } while( 0)
This macro never causes an assertion failure. It simply logs an error message. The macro takes a variable number of arguments:
_desc_: The description or format string for the assertion. Any additional arguments (_args_) are replacement arguments for % directives in the format string.
(Last Updated 3/20/2005)