I need to test whether the object is of type NSString
or UIImageView
. How can I accomplish this? Is there some type of "isoftype" method?
[yourObject isKindOfClass:[a class]] // 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.
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.
Creating a new object in Objective-C is usually a two-step process. First, memory has to be allocated for the object, then the object is initialized with proper values. The first step is accomplished through the alloc class method, inherited from NSObject and rarely, if ever, overridden.
If your object is myObject
, and you want to test to see if it is an NSString
, the code would be:
[myObject isKindOfClass:[NSString class]]
Likewise, if you wanted to test myObject
for a UIImageView
:
[myObject isKindOfClass:[UIImageView class]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With