Reputation: 1579
You would think this would return an NSString:
NSString *class = NSStringFromClass([[_array objectAtIndex:([_array count] -2)] class]);
NSLog(@"Is a kind of NSString: %@", ([[_class classForCoder] isSubclassOfClass:[NSString class]])? @"Yes" : @"No");
if ([class isEqualToString:@"MapViewController"]) {
[_appDelegate.navController0 pushViewController:_userListController animated:YES];
} else {
[_appDelegate.navController3 pushViewController:_userListController animated:YES];
}
But for some reason it doesn't, resulting in this crash:
Is a kind of NSString: No
-[NSKeyValueObservationInfo isEqualToString:]: unrecognized selector sent to instance 0x6e69080
Even when I try this:
NSString *class = (NSString *)[[_array objectAtIndex:([_array count] -2)] class];
It still doesn't return an NSString, resulting in this crash:
Is a kind of NSString: No
+[MapViewController isEqualToString:]: unrecognized selector sent to class 0xd4460
I knew going in, that the last example was a bit of a stretch, but I'm pretty clueless as to why I'm not getting a NSString returned from either one?
Upvotes: 0
Views: 1217
Reputation: 1579
When I was accessing the NSString "class" from outside a method, I would get all kinds of wacky errors. so what I did was add a little retain statement:
NSString *class = [NSStringFromClass([[_array objectAtIndex:([_array count] -2)] class]) retain];
and now it's working like a charm.
Upvotes: 2