Safe Type
SafeType is a convienient way to verify that an
NSObject
passed using id is the expected type when assigning the value to a pointer of a specific Objective-C type.
More...
Functions |
|
| id | SafeType (id obj, Class theClassType) |
|
Checks the type of an object passed as 'id' to verify it conforms to the expected Objective-C type.
More...
|
|
Detailed Description
SafeType is a convienient way to verify that an
NSObject
passed using id is the expected type when assigning the value to a pointer of a specific Objective-C type.
For example, if you are accessing an object from an NSNotification which you expect to be an NSString, you could use:
NSString * myString = SafeType([notification object], [NSString class]);
myString will be nil if the object is not an NSString or it will be a valid NSString.
Function Documentation
◆ SafeType()
| id SafeType | ( | id |
obj,
|
| Class |
theClassType
|
||
| ) |
Checks the type of an object passed as 'id' to verify it conforms to the expected Objective-C type.
- Parameters
-
objThe object to be checked theClassTypeThe type you expect the object to be.
This function will check obj to see if it is a kind of theClassType. If not, it will return nil.
- Returns
- obj or nil.