Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use the writeToFile method on an NSMutableDictionary?

I would like to use a method (writeToFile) only available for NSDictionary to a NSMutableDictionary object. So, how do I convert this NSMutableDictionary object to NSDictionary?

like image 463
Steve Avatar asked Sep 19 '11 23:09

Steve


3 Answers

NSMutableDictionary inherits from NSDictionary. So, writeToFile should be available to both classes.

like image 71
Daryl Teo Avatar answered Nov 01 '22 04:11

Daryl Teo


For those coming here genuinely looking for conversion from NSMutableDictionary to NSDictionary :

NSMutableDictionary *mutableDict = [[[NSDictionary alloc] initWithObjectsAndKeys:
                              @"value", @"key"] mutableCopy];

NSDictionary *dict = [NSDictionary dictionaryWithDictionary:mutableDict]; //there you have it
like image 13
Yoga Avatar answered Nov 01 '22 05:11

Yoga


NSMutableDictionary is a subclass of NSDictionary, so the writeToFile method should be available for your object without having to do any casting or conversions.

like image 7
Jeremy Flores Avatar answered Nov 01 '22 05:11

Jeremy Flores