Is it possible to get the name of a class into a string like this:
NSString *kls = (NSString *)[self.name class];
NSLog(@"%@", [kls isKindOfClass:[NSString class]] ? @"YES" : @"NO");
I can do: NSString *kls = [[[NSString alloc]initWithFormat:@"%@", [self.name class]]autorelease];
but that seems a bit long-winded to me.
It’s not for any task in particular, I’m just trying to learn more about the language as I go.
On the Mac, provided your object inherits from the
NSObjectclass rather than just implementing theNSObjectprotocol (the latter situation seems sort of unlikely), you should be able to call:classNameis defined in connection with Mac scripting support, so it is not available on the iOS version ofNSObject. In that case, you can probably do something like this:(I have only actually tried this on a Mac, though, so it’s possible it may not work correctly on an iOS device.)