I'm getting from the database dictionary in which there is one or more objects NSNull

54 views Asked by At

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!

3

There are 3 answers

0
Bohm On

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];
  }
}
2
Frankie On

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.

0
User511 On

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.