NSString converting to NSCFString - ios7

I have created a category of NSString Class , and i am trying to do some custom NSString operation .
My NSString object is converting to NSCFString and its crashing at calling custom NSString method.
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString stringByDeletingLastAndAddingFirstSlash]: unrecognized selector sent to instance 0xa6015e0'

Related

return Dictonary from Objective c file to Swift?

I am working with open cv and swift. While returning NSDictionary from Objective-C file to Swift getting an error.
2018-10-10 12:43:25.972927+0530 OPencvwithSwift[2430:618249] -[__NSFrozenDictionaryM length]: unrecognized selector sent to instance 0x1c022b6e0
2018-10-10 12:43:25.973704+0530 OPencvwithSwift[2430:618249] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSFrozenDictionaryM length]: unrecognized selector sent to instance 0x1c022b6e0'
*** First throw call stack:
(0x183eb6d8c 0x1830705ec 0x183ec4098 0x183ebc5c8 0x183da241c 0x1053c23d4 0x105360aa0 0x10585294c 0x104aec9a0 0x104ae287c 0x105cd51dc 0x105cd519c 0x105cd9d2c 0x183e5f070 0x183e5cbc8 0x183d7cda8 0x185d62020 0x18dd9c758 0x104af984c 0x18380dfc0)
libc++abi.dylib: terminating with uncaught exception of type NSException
Here is Objective c code -
- (NSDictionary *)predict:(UIImage*)img confidence:(double)confidence {
cv::Mat src = [img cvMatRepresentationGray];
int label;
NSLog(#"%d",label);
std::cout<<_labelsDictionary;
self->_faceClassifier->predict(src, label, confidence);
NSLog(#"%f",confidence);
NSMutableDictionary *dict = [[NSMutableDictionary alloc]initWithCapacity:10];
[dict setObject:[NSNumber numberWithInt:confidence] forKey:_labelsDictionary[#(label)]];
NSLog(#"%#",dict);
return dict;
}
Calling this function from Swift:
let result = facemodel?.predict(greyimage, confidence: confidence) // crash on this line
Your application crash while executing Objective-C method probably. Use break point inside Objective-C method and continue step-by-step so you will find your crash.
There is no way to crash assign pretict method's return dict to result variable. It gives [AnyHashable: Any] to result, so you will have a [AnyHashable: Any] type result object.
If I understand you correctly, before you use the dictionary,In other places it has been pointed to a string. so crash

How to set the value of UILabel in iphone?

I'm doing this to set the value in UILabel:
NSMutableDictionary *responseDict = [responseString objectFromJSONString];
self.pkrLbl.text= [responseDict objectForKey:#"amount"];
and I'm getting this error:
[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0x9440310
2013-05-16 15:23:34.281 EasyLoadPakistan[20341:19a03] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0x9440310'
Please help me how can I set value in UIlabel
A UILabel expects a string (specifically NSString or one of its subclasses), and you are passing it a number (an NSNumber instance).
Convert the number to a string first, then set the label to that string:
NSNumber *n = [responseDict objectForKey:#"amount"];
NSString *stringVersion = [n stringValue];
self.pkrLbl.text = stringVersion;
If you prefer to have it all on one line, you can omit the variables and just chain the stringValue call. The approach shown above tends to facilitate debugging, though (you can for instance set a breakpoint and have a look at your variables).

IntValue of an object from array causing errors

I am having a slight code problem. I have an array but when I pull data out of it, I need it in the form of an int. To do this, I tried to use:
int main_id = [[courses valueForKey:#"id"] intValue];
but this gives me the error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI intValue]: unrecognized selector sent to instance 0x6b438d0'
*** First throw call stack:
(0x16ac022 0x183dcd6 0x16adcbd 0x1612ed0 0x1612cb2 0x4bf8 0x4fdd 0xdea1e 0xddfec 0x104f1d 0xef1cb 0x105df1 0x105e0d 0x105ea9 0x446f5 0x4473c 0x15596 0x16274 0x25183 0x25c38 0x19634 0x1596ef5 0x1680195 0x15e4ff2 0x15e38da 0x15e2d84 0x15e2c9b 0x15c65 0x17626 0x36ed 0x2695 0x1)
terminate called throwing an exception
I have found the answer. I was using an NSArray
NSArray *array;
That had another nsarray in it. I was trying to call the intvalue of a NSArray.

iOS: replace an object inside an array of array

My code is:
[[arrayOne objectAtIndex:indexSelected] replaceObjectAtIndex:1 withObject:new];
NSLog(#"indexSelected:%d", indexSelected); // = 0
NSLog(#"new:%#", new); // = 26
indexSelected is an int and new is a string
When I try to do this I have an exception that says: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance 0x1cee60'
Why?
This is because NSArray is immutable. Use an NSMutableArray.

When I am replacing or inserting an object into nsmutable array, I am getting an Exception

While replacing or inserting into an NSMutable array, I am getting exception as:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '*** -[NSCFArray replaceObjectAtIndex:withObject:]: mutating method sent to immutable object'
[list replaceObjectAtIndex:indexRow withObject:editcontacts];
//or
[list insertObject:editcontacts atIndex:indexRow];
You are still using an NSArray instead of an NSMutableArray. You need to allocate list as such:
NSMutableArray *list = [[NSMutableArray alloc] init];
See this question