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

StackOverflow https://stackoverflow.com/questions/19270232

  •  30-06-2022
  •  | 
  •  

Question

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) { ... }];

  ...
}
Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top