Xcode call stack - ios

I'm getting an exception while running iOS app in simulator
2013-09-16 18:03:44.346 DEV[26529:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSDecimalNumber isEqualToString:]: unrecognized selector sent to instance 0xf98fc70'
*** First throw call stack:
(0x17bf012 0x1c38e7e 0x184a4bd 0x17aebbc 0x17ae94e 0x1b813 0x1c4c705 0x653920 0x6538b8 0x714671 0x714bcf 0x713d38 0x917213 0x1787afe 0x1787a3d 0x17657c2 0x1764f44 0x1764e1b 0x29db7e3 0x29db668 0x65065c 0x25c9 0x2505 0x1)
UPD:
Exception is caused by the following code:
if([self.media.idtype isEqualToString:IMAGETYPE])
Where idtype is #property(retain, nonatomic) NSString *idtype; and IMAGETYPE is static NSString *VIDEOTYPE = #"2";
How can I see function names instead of addresses?

isEqualToString can compare two NSstrings not the other type of data that u are comparing which is NSDecimalNumber
convert your NSDecimalNumber to nsstring then do this
NSDecimalNumber* dec1;
NSString* str;
str = dec1.stringValue;
NSString *str2=#"world";
[str isEqualToString:str2];

There is some where in your code you are setting the value of property idtype (self.media.idtype). This must be the source of the problem:
Possible Problems could be Extracting contents from Webservice and while parsing you might be assigning it to the self.media.idtype object.

Related

Handle either a string or int in JSON response

If catData is a dictionary returned from a rest API call:
NSString* catId = catData[#"id"];
This is fine if catData[#"id"] is a string. Not so much if it's an int or something else.
I tried this:
NSString* catId = [catData[#"id"] stringValue];
But that results in this:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSTaggedPointerString stringValue]: unrecognized selector sent to instance 0xa000030383130365'
How can I properly handle any type of value and get it converted to the string that I need?
I'm using AFNetworking with AFJSONResponseSerializer.
instead of using
NSString* catId = [catData[#"id"] stringValue
both case use
NSString* catId = catData[#"id"];
crash happen because you are trying to convert string to string value

how to access single JSON value for key in Objective-C

I am new to Obj-C and somehow I can get the output of a JSON-Request due to difficulties with arrays, dictionareis and syntax. It would be great if someone could get me on my way.
NSLog(#"JSON Feed: %#", self.classified);
NSDictionary *test = self.classified;
NSLog(#"andy %#", [test objectForKey:#"text"]);
this throws an exception :
JSON Feed: (
{
text = "test text";
}
)
2014-06-05 17:25:28.170 Nerdfeed[2321:4107] -[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x10b988da0
2014-06-05 17:25:28.173 Nerdfeed[2321:4107] * Terminating app due to uncaught exception
I now tried to find a solution for hours but cant fix it. Thank you so much for any help.
self.classified seems to be a NSArray with a single item (and not a NSDictionary). Try [[self.classified firstObject] objectForKey:#"text"]

ObjC searching for # in a string (iOS # escape code)

I'm searching an NSString with an email to find the # character. Here's the code:
NSRange range = [string rangeOfString:#"#"];
if (range.location != NSNotFound) // do stuff
Here's the error I'm getting...
-[__NSCFNumber rangeOfString:]: unrecognized selector sent to instance 0x1e51c550
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber rangeOfString:]: unrecognized selector sent to instance 0x1e51c550'
Your string variable points to an instance of NSNumber, not an instance of NSString. You are initializing it incorrectly.

What is wrong with my data format?

I am using a tutorial app as a reference and I'm trying to make an app that converts shoe sizes from the U.S. shoe size to other the following countries: Europe, United Kingdom, and Japan.
I have a warning that pops up in my ViewController.m file stating:
Data argument not used by format string
on the following code:
NSString *resultString = [[NSString alloc] initWithFormat: #"3f USS = 3f #", size, result, _countryNames[row]];
When I run the app, my DeBug Area pops with the following:
2013-07-15 10:50:07.377 ShoeSizeConverter[9617:c07] -[UIView numberOfComponentsInPickerView:]: unrecognized selector sent to instance 0x7170c10
2013-07-15 10:50:07.379 ShoeSizeConverter[9617:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView numberOfComponentsInPickerView:]: unrecognized selector sent to instance 0x7170c10'
* First throw call stack:
(0x1c92012 0x10cfe7e 0x1d1d4bd 0x1c81bbc 0x1c8194e 0xc634 0xd25f 0x642dd 0x10e36b0 0x228efc0 0x228333c 0x228eeaf 0x1032bd 0x4bb56 0x4a66f 0x4a589 0x497e4 0x4961e 0x4a3d9 0x4d2d2 0xf799c 0x44574 0x4476f 0x44905 0x4d917 0x1196c 0x1294b 0x23cb5 0x24beb 0x16698 0x1beddf9 0x1bedad0 0x1c07bf5 0x1c07962 0x1c38bb6 0x1c37f44 0x1c37e1b 0x1217a 0x13ffc 0x1ecd 0x1df5)
libc++abi.dylib: terminate called throwing an exception
I have a warning that pops up in my ViewController.m file stating
"Data argument not used by format string" on the following code:
You need to add percent signs before your format specifiers. Instead of 3f, you need %3f and so on. So your format string should be:
#"%3f USS = %3f %#"
The warning means that you are including data arguments (size, result, _countryNames[row]) but the format string has no reference to the data arguments. It looks like you are not including your percent signs, and need something like this:
NSString *resultString = [[NSString alloc] initWithFormat: #"%3f USS = %3f %#", size, result, _countryNames[row]];
I believe the exception means that you have set your view as the data source of your UIPickerView, and your view does not respond to the numberOfComponentsInPickerView method. You probably mean to set the data source of your UIPickerView to the view controller (probably self) and make sure your view controller implements numberOfComponentsInPickerView.

AFNetworking does not returns NSString if the value is contains only digits

I'm trying to receive a certain value in a json using AFNetworking. The value only contains digits and I want to receive it as a NSString. When I compare the received value, I get a exception (exception is also mentioned later in this post)
here is the coding producing the error.
NSArray *overallGameResultsArray = [resultDictionary valueForKey:#"overall_game_results"];
winCountDictionary = [[NSDictionary alloc] init];
for (NSDictionary *gameResultsDictionary in overallGameResultsArray)
{
NSString *userId = [gameResultsDictionary valueForKey:#"winner_user_id"];
NSString *winCount = [gameResultsDictionary valueForKey:#"win_count"];
if ([winCount isEqualToString:#"0"])
{
NSLog(#"0 wins");
}
}
I don't get the exception if the "if comparison" is commented. The win_count only consists of digits in the jSON response.
Following is the exception error I'm getting.
2012-10-10 15:41:35.086 FMB[3549:c07] -[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0x7230af0 2012-10-10 15:41:35.086 FMB[3549:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0x7230af0'
*** First throw call stack: (0x1638012 0x1345e7e 0x16c34bd 0x1627bbc 0x162794e 0x11e03 0x20583 0x1fab4 0x245053f 0x2462014 0x24527d5 0x15deaf5 0x15ddf44 0x15dde1b 0x26997e3 0x2699668 0x28d65c 0x2512 0x2445) libc++abi.dylib: terminate called throwing an exception
i think you'll have to do :
NSString *winCount=[NSString stringWithFormat:#"%d",[[gameResultsDictionary valueForKey:#"win_count"]intValue];
With this, you get the number value into the winCount NSString, and then you can use isEqualToString method
I suppose you use JSON. Then the type of the object is determined by JSON encoding. If there are " around, it's a string. If it's a number and you want string there, change how the data is encoded on the server.
However, in this context, using a number makes more sense. You should change the implementation in the following way.
NSNumber* winCount = [gameResultsDictionary valueForKey:#"win_count"];
if ([winCount intValue] == 0) { //this would actually work for both NSNumber and NSString
NSLog(#"0 wins");
}
Comparing numbers using string comparison is always a hint that you are doing something wrong.
The exception is thrown because you expect an object to be an NSString but actually is an NSNumber, so you try to call isEqualToString: on the NSNumber which doesn't implement the method.
Since you know that winCount is always a number and apparently the JSON deserializer that AFNetworking uses box the numbers in the response into NSNumber objects, you could easily grab a string out of the object like this:
NSString *winCount = [[gameResultsDictionary valueForKey:#"win_count"] stringValue];
Now you have a string representation of your number and you can therefor perform isEqualToString:
Also note that a more elegant solution might be to receive your objects as ids, find their class and do a comparison based on the class determined.

Resources