0

I'm getting from the database dictionary in which there is one or more objects NSNull. In the future, I can not in any way to work with him as the app crash. I tried many ways to remove from the dictionary NSNull objects, method removeObjectForKey but any attempt to do this I get an error that is an array of reason:

- [__ NSArrayM removeObjectForKey:]: unrecognized selector sent to an instance

And I can not remove these objects by method the array removeObjectAtIndex as this dictionary. I only thought of how to do this is to remove these objects by type. Is it possible to do so, remove the object from the dictionary that match NSNull type? Or maybe there is another solution to this problem?

Thank you for any help!

adjuremods
  • 2,938
  • 2
  • 12
  • 17
Sasha Tsvigun
  • 311
  • 5
  • 15
  • 2
    Post the contents of your source 'dictionary', or 'array', or whatever it might be. – Frankie Nov 22 '16 at 00:13
  • `NSArrayM` is clearly a mutable array (`NSMutableArray`), not a dictionary. arrays are index based, dictionaries are key based. – vadian Nov 22 '16 at 05:40

3 Answers3

0

This loop (adapted from this post) should help you substitute the NSnull entries with a string of your choice (forgive typos, I am not in front of my computer).

for(NSString *key in yourDictionary) {
  id dictionaryEntry= [yourDictionary objectForKey:key];
  if(!dictionaryEntry) {
     [newDictionary setObject:@"string" forKey:key];
  } else {
     [newDictionary setObject:[yourDictionary objectForKey:key] forKey:key];
  }
}
Community
  • 1
  • 1
Alex
  • 995
  • 12
  • 25
0

You say:

And I can not remove these objects by method the array "removeObjectAtIndex" as this dictionary.

Unfortunately your error:

[__ NSArrayM removeObjectForKey:]: unrecognized selector

Does not agree with you. You have an array. And the reason you cannot use removeObjectAtIndex is because it is immutable.

Frankie
  • 11,508
  • 5
  • 53
  • 60
  • the problem is that I keep in the database objects in the dictionary and I returned dictionary. but when there gets nsnull then returns an array – Sasha Tsvigun Nov 22 '16 at 09:05
  • Then that sounds like a different problem. The solution to the problem above is that you're trying to call dictionary methods on an array. – Frankie Nov 22 '16 at 14:54
0

You are removing a key from an array

Note down that you cannot remove a key from an array. Than this error is obvious.

Also for removeObjectAtIndex

Make sure your array should be mutable. Then you can use removeObjectAtIndex.

Hope it works for you.

User511
  • 1,456
  • 10
  • 28