Why 'YYModel' lead project crash on iOS8? - ios

My YYModel is managed by cocoapods. I use YYModel to convert json to model.There is my code where use YYModel:
for (NSDictionary *dic in labelArray) {
CQMenuButtonModel *model = [[CQMenuButtonModel alloc]init];
[model yy_modelSetWithDictionary:dic];
[modelsArray addObject:model];
}
It crashed at [model yy_modelSetWithDictionary:dic];,and the console showed:'-[CQMenuButtonModel yy_modelSetWithDictionary:]: unrecognized selector sent to instance 0x18b47d20'
However, it work fine on iOS9 and iOS10.
At first I think maybe the newest YYModel doesn't fit iOS8, so I change the YYModel's version to 0.9, However,it's crash on iOS8 too.
What confused me most is that why it crash on iOS8 but work fine on iOS9 and iOS10,What's more,I really don't understand why console show me :unrecognized selector sent to instance 0x18b47d20

I replaced YYModel with JSONModel at last then it work fine.

Related

How to read crash report in HockeyApp

I'm testing the framework HockeyApps for testing apps with iOS, it seems I added successfully my app.
I added a code which is triggered after the user touches a button, the code is very simple:
- (IBAction)didClickAuthenticateOptions:(id)sender {
NSString *s = #"x";
id obj = s;
NSArray *arr = obj;
NSLog(#"the array has the following lenght:");
NSLog(#"%lu", (unsigned long)[arr count]);
}
this code will terminate with a crash on my app.
I installed and executed my app normally on my iPhone, and the crash report was sent to my site:
but when I opened the crash report, I expected to get information about the file, method, line of code that provoked the crash
when I clicked on "view raw log" I got all this:
raw log
How to find the method, line and code that provoked the crash in all that log???
thanks in advance for the support
This is because you did not yet upload the correct dSYM files to HockeyApp. They are needed to translate the cryptic memory addresses back to readable filenames, method names, and line numbers.
There some more info on how to find the correct dSYM here.

App crashing when trying to setValue in NSMuableDictionary

My app is crashing when I try to set value in NSMutableDictionary.
Here is the code below which demostrate the crash, I am not able to find out any crash log also in the console.
NSArray *b =[[a objectAtIndex:1] valueForKey:#"value"];
NSMutableDictionary *b1 =[b objectAtIndex:0];
NSString *str = self.tes;
[b1 setValue:str forKey:#"value"];
Please help me regarding this.
b1 Dictionary log
{
question = "vale";
type = a;
}
setValue:forKey: is part of the NSKeyValueCoding protocol, which among other things, lets you access object properties from the likes of Interface Builder. setValue:forKey: is implemented in classes other than NSDictionary.
setObject:forKey: is NSMutableDictionary's reason to exist. Its signature happens to be quite similar to setValue:forKey:, but is more generic (e.g. any key type).
So in your case just replace all setValue:forKey with setObject:forKey and valueForKey: with objectForKey:
--
Difference between objectForKey and valueForKey?
So you said you are getting EXC_BAD_ACCESS crash. Try turning on Zombies in Xcode’s Scheme editor. See Enable and Debug Zombie objects in iOS using Xcode 5.1.1. That question explains how to use it, but you don’t need to run Instruments as mentioned there.
Then just run the app and Xcode will show you the reason of EXC_BAD_ACCESS. Don’t forget to turn Zombies off after you don’t need it.
The name Zombie comes from the fact that under this mode all deallocated objects will be marked and will be kept as special regions of memory (not live, not dead, zombies). Once your code attempts to use such deallocated object, Xcode will notice and print helpful message.

All of a sudden: -[__NSArrayM popObjectForKey:]: unrecognized selector sent to instance

I was developing an app, at some stage this error came out:
-[__NSArrayM popObjectForKey:]: unrecognized selector sent to instance
I've undone the latest edits to see what was wrong...but the error was still there.
So I've undone even more edits, but the error was still there.
Tried to delete and add back the framework where I thought the error could come from, error still there. (it's KinveyKit framework)
Tried to substitute the line of code where the app would throw the error with another one that was surely working: even that one was throwing the error.
I downloaded an older Git of the app (that was definitely working a few days ago) on a different folder, run that and: same error.
Uninstalled and reinstalled Xcode: error still there.
But: if I run other apps with similar code, nothing goes wrong.
Does anybody have any idea?
I post here the code, that throws me the error, just to give you an idea...but I don't think there's anything wrong in the code since it's always been working before.
.h
#property (strong, nonatomic) KCSAppdataStore *store;
.m
- (void)viewDidLoad
{
...
_store = [KCSAppdataStore storeWithOptions:#{ KCSStoreKeyCollectionName : #"AnEntity",
KCSStoreKeyCollectionTemplateClass : [AnEntity class]}];
[_store queryWithQuery:[KCSQuery query]
withCompletionBlock:^(NSArray *objectsOrNil1, NSError *errorOrNil) { ... }];
...
}
Cool -- being sarcastic
I spent the afternoon rebuilding the app from a new project, copy pasting the code...
Now I opened the older one once again, tried to run it just...just to try once again, knowing it would crash cause I haven't change a word it already crashed every other time I tried earlier this morning, and.... surprise: runs again. No errors.
-.-'' Solution to my question then? No idea. Still thinking it was some cache problem that eventually got solved through out the day but not while I was trying to solve it.
If anybody has had similar experiences or has some further idea, feel free to add something, always good to be prepared for next time something like this happens.
I had a similar issue that appeared to be caused by a corrupted KCSUser object written to the keychain. The popObjectForKey method appears to get called any time you call [KCSUser activeUser]. I was able to get this fixed by adding the code below first thing in application DidFinishLaunchingWithOptions:. Be sure you aren't calling [KCSUser activeUser] at any point before the following code has a chance to run.
NSArray *secItemClasses = #[(__bridge id)kSecClassGenericPassword,
(__bridge id)kSecClassInternetPassword,
(__bridge id)kSecClassCertificate,
(__bridge id)kSecClassKey,
(__bridge id)kSecClassIdentity];
for (id secItemClass in secItemClasses) {
NSDictionary *spec = #{(__bridge id)kSecClass: secItemClass};
SecItemDelete((__bridge CFDictionaryRef)spec);
}
This appears to clear/reset the keychain. After you run it once, remove it and you app should operate normally.

ios unrecognized selector [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
-[__NSCFDictionary JSONRepresentation]: unrecognized selector sent to instance
I use SBJson ( http://stig.github.com/json-framework/ ) in two of my project. Therefore I downloaded the code and copied it into my first project so that I can do something like this
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
[dict setValue:email forKey:#"email"];
[dict setValue:password forKey:#"password"];
NSString* json = [dict JSONRepresentation];
Now for my second and new project I did the same. I copied all the source files from SBJson into my new project and used the exact same code as above. But now when the program comes to line NSString* json = [dict JSONRepresentation]; I get the following error message:
-[__NSCFDictionary JSONRepresentation]: unrecognized selector sent to instance 0x689c710
What am I doing wrong in my second project?
Make sure that all the files have been added to the target.
Since iOS 5 you don't need an external library to use JSON, This tutorial could help you with that.
That error is because you are telling to dict, which is an instance of NSMutableDictionary, to perform a method called JSONRepresentation. dict doesn't know how to do that. I haven't work with that library but I would guess that you need to make an instance of SBJSON parser and then send dict as parameter. I found this and this tutorials, I hope they can help you.

JSON: NSString stringWithContentsOfURL... with null in stream, crashes

Environment: iOS 4.3+ using Xcode 4.3+
I'm always getting an iOS/Xcode crash when I implement the following string that returns data with nulls in it:
[NSString stringWithContentsOfURL:myURL encoding:NSUTF8StringEncoding error:&error];
NSDictionary *myResult = (NSDictionary *)[myString JSONValue];
The result:
-[NSNull isEqualToString:]: unrecognized selector sent to instance 0x17315e8
When the data stream contains no nulls (mostly), it works fine.
Is this a known problem?
Any remedy?
You can also fix the data coming in from the source. In almost all of my web service interaction, I use COALESCE on queries and SP's to make sure that the data coming out is always consistent.

Resources