0

My warning in Xcode :

Incompatible pointer types initializing 'NSMutableDictionary *' with an expression of type 'NSDictionary *'

For this code :

NSMutableDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:
                                 [NSNumber numberWithLongLong:byteCount],@"bytes",
                                 [NSNumber numberWithLong:fileCount],@"files",nil];
    [dict writeToFile:countsPath atomically:YES];

Thank you in advance for your help

4
  • 1
    yeah can't be any clearer than that: NSMutableDictionary* dict = [NSDictionary... different type Sep 13, 2013 at 17:26
  • 1
    It's telling you exactly what's happening -- your l-value is an NSMutableDictionary, but you're initializing it with a NSDictionary -- inconsistent types.
    – jstevenco
    Sep 13, 2013 at 17:27
  • Since all you are doing is writing the dictionary, change dict to of type NSDictionary.
    – rmaddy
    Sep 13, 2013 at 17:30
  • HJMOFileCache problem. Nicely done and a good question. Thanks Mar 10, 2014 at 9:44

4 Answers 4

5

change this word:

NSMutableDictionary

to

NSDictionary

and fix all errors it will cause

1
1

You cannot initialize an NSMutableDictionary to be [NSDictionary .... You can, however, assign an NSMutableDictionary to an NSDictionary after they have been created and initialized. The reason is because NSMutableDictionary is a subclass of NSDictionary, so it can be assigned that way, but not the other way around.

1

I also made a mistake like this:

  NSMutableDictionary *data = @{ @"value" : value, @"contentArray" : arrayData };

Its very tempting to make this problem. :D

0

NSMutableDictionary is a subclass of NSDictionary and you are trying the vice-versa.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy