1

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

  ...
}
BkdD
  • 593
  • 1
  • 7
  • 13
  • What is popObjectForKey ? Where are you calling it - it's not inside a code you pasted. – Grzegorz Krukowski Oct 09 '13 at 11:49
  • yea it's not inside my code at all... I guess it's inside of KinveyKit framework, somewhere... but don't know where, and anyways it's surely not wrong there cause it's a well working framework and was working for me up to last evening. – BkdD Oct 09 '13 at 13:30
  • You are calling popObjectForKey on NSMutableArray - check if this how how they implemented it or maybe it should be special type not standard NSMutableArray. – Grzegorz Krukowski Oct 09 '13 at 13:31
  • Uh, I see... __NSArrayM means NSMutableArray. I just performed a search and I use no "popObjectForKey" in my whole project, and can't see where and how they're using it, cause it's their private code. I could write them to ask, but still is weird that it was working, then all of a sudden started not to work anymore, not with this project, neither with the older versions of it. Could it be any kind of cache issue? I tried cleaning the project from Xcode, deleting the cache through command line, reinstalling Xcode, but nothing – BkdD Oct 09 '13 at 13:43
  • If you don't see it anywhere in project - it's impossible it was working :) – Grzegorz Krukowski Oct 09 '13 at 14:26

2 Answers2

1

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.

BkdD
  • 593
  • 1
  • 7
  • 13
1

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.

natenash203
  • 699
  • 6
  • 15