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];
Related
Ride[source_name]=2152,%20Mohali%20Stadium%20Rd,%20Phase%2010,%20Sector%2064,%20Sahibzada%20Ajit%20Singh%20Nagar,%20Punjab%20160062,%20भारत
This parameter is causing crash while running in Hindi while working fine with Spanish and English. Please suggest me on it. Crash description is as following:-
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not
satisfying: URLString'
Check with this
Objective - C
NSString *string = #"भारत";
NSString *encoded = [string stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
Swift 3.0
let string = "भारत"
let urlString = string.addingPercentEncoding( withAllowedCharacters: . urlUserAllowed)
Output :: %E0%A4%AD%E0%A4%BE%E0%A4%B0%E0%A4%A4
Add below line of code to avoid invalid parameters in url.
NSString *str = ...; // Your URL
NSCharacterSet *set = [NSCharacterSet URLHostAllowedCharacterSet];
NSString *result = [str stringByAddingPercentEncodingWithAllowedCharacters:set];
Deprecated Code Before ios 9.0 :
NSString *str = ...; // Your URL
NSString *urlAsString = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
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"];
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?
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.
I want to check the last 2 bytes of files in my app to make sure they are not corrupt .jpg's
rangeOfData:options:range: looks like a good option, but I am having a hard time figuring out how to get a proper NSRange. The range I am looking for is starting near the end of the NSData, up to the end.
Here is what I have so far:
NSData *imageData = [NSData dataWithContentsOfFile:filePath];
NSRange range = {([imageData length]-8),[imageData length]};
NSString *str = #"FFD9";
NSData *jpgTest = [str dataUsingEncoding:NSUTF8StringEncoding];
NSRange found = [imageData rangeOfData:jpgTest options:NSDataSearchBackwards range:range];
Here is the error I get:
** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSConcreteData rangeOfData:options:range:]: range {14954, 14962} enxceeds data length 14962'
How do I properly get the range to search the last few bytes of my NSData?
The second member of NSRange is not the end point of the range but its length. So in your case it should be:
NSRange range = {([imageData length]-8), 8};