[NSConcreteValue rangeOfString:]: unrecognized selector sent to instance - ios

I try get a range from a string,like:
NSString *str = change[#"new"];
NSLog(#"%#",str);// it will be printed
NSRange range = [str rangeOfString:#"NSPoint"];//the exception uncaughted
NSLog(#"%lu",range.location);
But then i got a exception:
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[NSConcreteValue
rangeOfString:]: unrecognized selector sent to instance
0x7fc258c4f8f0'
And it puzzled me that if i change the strto #"NSPoint: {0, 0}"
It will work?!
Omg, why?

try
NSString *str = [NSString stringWithFormat:#"%#",change[#"new"]];
instead of
NSString *str = change[#"new"];

Related

Unrecognized selector sent to instance On UILabel

I am parsing JSON and get the value.Store value as NSString and when I want to show on UILabel app crashes with
unrecognized selector sent to instance 0x7b070470`
NSString *idvalue = [jsonResponse objectForKey:#"id"];`
labl_id.text =idvalue;
NSLog(#"id value%#",idvalue);
output: id value 6
please let me know how to fix this
thanks
mb you get NSNumber
NSString *idvalue = [[jsonResponse valueForKey:#"id"] stringValue];

iOS, 'NSInvalidArgumentException' on NSString

I have data coming in from a JSON source.
The value of key hour is an integer:
{"busy": {"day":"monday", "month":"February", "hour":20}}
Here i make use of the values
NSString *hour = [[self.stats valueForKey:#"busy"] valueForKey:#"hour"];
NSString *day = [[self.stats valueForKey:#"busy"] valueForKey:#"day"];
NSString *month = [[self.stats valueForKey:#"busy"] valueForKey:#"month"];
NSLog(#"hour: %#", hour);
NSLog(#"day: %#", day);
NSLog(#"month: %#", month);
self.busyHour.text = (NSString *)hour;
self.busyDay.text = day;
self.busyMonth.text = month;
I get the correct output from the NSLogs of all 3 of the values, yet when i attempt to assign self.busyHour.text i get the following error.
-[__NSCFNumber length]: unrecognized selector sent to instance 0xb000000000000093
2015-02-16 10:30:41.133 changeView[1494:411656] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]
NSInteger hour = [[[self.stats valueForKey:#"busy"] valueForKey:#"hour"] integerValue];
self.busyHour.text = [NSString stringWithFormat:#"%i", hour];
This is really self explanatory... you're assigning hour to self.busyHour and you're casting it - did you check it's really an NSString before doing so?

NSInvalidArgumentException with stringByAppendingPathComponent

i have a bundel settings with a string : version
in my bundle settings version = 2.9.1
in my project, if i use this code, all is good :
NSString *path = [documentsDirectory stringByAppendingPathComponent:#"ma/V_2.9.1/gma2/fixture_layers/ifocus.xml"];
if i use this code :
NSString *path = [documentsDirectory stringByAppendingPathComponent:(#"ma/V_%#/gma2/fixture_layers/ifocus.xml", version)];
i have this error :
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITextField length]: unrecognized selector sent to instance 0x9753190'
NSString * path = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:#"ma/V_%#/gma2/fixture_layers/ifocus.xml", version]];
Since you're already including multiple /'s in your string, there's no advantage to using stringByAppendingPathComponent. So you may as well just use:
NSString* path = [documentsDirectory stringByAppendingFormat:#"ma/V_%#/gma2/fixture_layers/ifocus.xml", version];
Another option, that gives you the benefit of stringByAppendingPathComponent, is to break it right down like this:
NSString* path = [[[[[documentsDirectory stringByAppendingPathComponent:#"ma"] stringByAppendingPathComponent:[NSString stringWithFormat:#"V_%#", version]] stringByAppendingPathComponent:#"gma2"] stringByAppendingPathComponent:#"fixture_layers"] stringByAppendingPathComponent:#"ifocus.xml"];
But that's kind of ugly.

iOS app crashing with error: NSCFNumber stringByReplacingOccurrencesOfString:withString: unrecognized selector sent to instance

Our iOS app terminates with an error of [__NSCFNumber stringByReplacingOccurrencesOfString:withString:]: unrecognized selector sent to instance 0x1755e090.
We're testing on an iPhone 5 w iOS 7.
It crashes on this line: [self parseDictionary:notificationMessage intoJSON:jsonStr].
Method containing this line:
- (void)notificationReceived {
NSLog(#"Notification received");
if (notificationMessage && self.callback)
{
NSMutableString *jsonStr = [NSMutableString stringWithString:#"{"];
[self parseDictionary:notificationMessage intoJSON:jsonStr];
if (isInline)
{
[jsonStr appendFormat:#"foreground:\"%d\"", 1];
isInline = NO;
}
else
[jsonStr appendFormat:#"foreground:\"%d\"", 0];
[jsonStr appendString:#"}"];
NSLog(#"Msg: %#", jsonStr);
NSString * jsCallBack = [NSString stringWithFormat:#"%#(%#);", self.callback, jsonStr];
[self.webView stringByEvaluatingJavaScriptFromString:jsCallBack];
self.notificationMessage = nil;
}
}
-(void)parseDictionary:(NSDictionary *)inDictionary intoJSON:(NSMutableString *)jsonString
{
NSArray *keys = [inDictionary allKeys];
NSString *key;
for (key in keys)
{
id thisObject = [inDictionary objectForKey:key];
if ([thisObject isKindOfClass:[NSDictionary class]])
[self parseDictionary:thisObject intoJSON:jsonString];
else
[jsonString appendFormat:#"\"%#\":\"%#\",",
key,
[[[[inDictionary objectForKey:key]
stringByReplacingOccurrencesOfString:#"\\" withString:#"\\\\"]
stringByReplacingOccurrencesOfString:#"\"" withString:#"\\\""]
stringByReplacingOccurrencesOfString:#"\n" withString:#"\\n"]];
}
}
Stack trace (along with one debugging line to show the variable value):
2014-01-07 16:32:36.980 Wopple[195:60b] Notification received
Printing description of self->notificationMessage:
{
"_" = "gHf8EeO3_ZDiugJkgA";
aps = {
alert = "hi foo bar right";
badge = 3;
};
}
2014-01-07 16:33:22.774 Wopple[195:60b] -[__NSCFNumber stringByReplacingOccurrencesOfString:withString:]: unrecognized selector sent to instance 0x1755e090
2014-01-07 16:33:22.776 Wopple[195:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber stringByReplacingOccurrencesOfString:withString:]: unrecognized selector sent to instance 0x1755e090'
*** First throw call stack:
(0x308c3e83 0x3ac246c7 0x308c77b7 0x308c60af 0x30814dc8 0x88da5 0x88d1f 0x88915 0x8757b 0x3335ec93 0x3335f75d 0x340d0b37 0x3088e777 0x3088e713 0x3088cedf 0x307f7471 0x307f7253 0x3552b2eb 0x330ac845 0x7f5d3 0x3b11dab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
When you're using:
[[[[inDictionary objectForKey:key]
stringByReplacingOccurrencesOfString:#"\\" withString:#"\\\\"]
stringByReplacingOccurrencesOfString:#"\"" withString:#"\\\""]
stringByReplacingOccurrencesOfString:#"\n" withString:#"\\n"]];
You're assuming that objectForKey is going to return an NSString object. But, in the case where your app is crashing, the object returned is actually an NSNumber.
You should use isKindOfClass: to determine the object type, or use stringValue on your NSNumber to get a string representation of the object.

'NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds'

Im inserting a string into a NSMutableString like as
NSMutableString *string = (NSMutableString *)self.label.text;
[string insertString:#"New " atIndex:0];
these line of codes working properly iOS 6 device. but in iOS 7 it throws an exception as Terminating app due to uncaught exception 'NSRangeException', reason: 'NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds' (i'm running ios 6 app in ios 7 device).
can any body tell why it's happening? please.
thanks
You can't convert an NSString to an NSMutableString simply by casting. Do this instead:
NSMutableString *string = [self.label.text mutableCopy];

Resources