I have some code that is supposed to return an NSString. Instead it is sometimes returning an NSArrayReverseEnumerator. This causes an unrecognized selector sent to instance exception.
NSString *tFirstName = nil;
NSString *tUsername = ((NSString*)[self.userObject objectForKey:USER_NAME]).length > 0 ? [self.userObject objectForKey:USER_NAME] : [self.userObject objectForKey:USER_USERNAME];
NSRange spaceRange = [tUsername rangeOfString:@" "];
if (spaceRange.location == NSNotFound) {
tFirstName = tUsername;
} else {
tFirstName = [tUsername substringToIndex:spaceRange.location];
}
return tFirstName;
I'm then setting a UITextField text property to what is returned which causing an exception.
The exception is:
-[__NSArrayReverseEnumerator isEqualToString:]: unrecognized selector sent to instance 0xf1b8190
Here is the last few lines of the stack trace:
CoreFoundation 0x381208bf __exceptionPreprocess + 163
1 libobjc.A.dylib 0x31c061e5 objc_exception_throw + 33
2 CoreFoundation 0x38123acb -[NSObject doesNotRecognizeSelector:] + 175
3 CoreFoundation 0x38122945 ___forwarding___ + 301
4 CoreFoundation 0x3807d680 _CF_forwarding_prep_0 + 48
5 UIKit 0x354dc20d -[UILabel setText:] + 45
6 Trivial 0x000873c9 -[vcGameOver viewDidLoad] (vcGameOver.m:45)
7 UIKit 0x355117ff -[UIViewController view] + 167
userObject looks like this normally, haven't been able to reproduce in the debugger yet to see what it looks like at the time of exception:
userObject looks like this:
(PFUser *) $1 = 0x0be86fb0 <PFUser:MTsJR1DKuS> {
answeredCorrect = "<PFRelation: 0xa847f30>";
centsEarned = "-2353";
centsPaidFor = 5000;
centsUsed = 4193;
correctAnswers = 1454;
earnedCoinDate = "2012-06-12 19:42:44 +0000";
eloRating = 1262;
iq = 119;
lastPlayedDate = "2012-06-12 19:15:46 +0000";
locale = en;
losses = 10;
name = "Matt Hudson";
status = 0;
username = Inturbidus;
wins = 8;
wrongAnswers = 1157;
}
My question is, which line in my code above could possible return an NSArrayReverseEnumerator?