Quote:
Originally Posted by Karl6669
Hi, I am trying to create a filtering effect for a tableview but am struggling with one thing. I have a plist file containing multiple NSDictionary's (Manufacturer Names) with multiple sub-NSDictionary's (Model #'s). I am trying to remove specific keys (Model #'s) when the select a certain filter. My plist looks like this:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>2400</key>
<dict>
<key>Model</key>
<string>2400</string>
<key>Gauge</key>
<string>24</string>
<key>Thickness</key>
<string>2"</string>
<key>Insulated</key>
<string>Non-Insulated</string>
<key>Material</key>
<string>Steel</string>
<key>Panel Design</key>
<string>Ribbed</string>
<key>Image</key>
<string>Steel-Craft 2400.png</string>
<key>Discontinued</key>
<true/>
</dict>
<key>TD-138</key>
<dict>
<key>Model</key>
<string>TD-138</string>
<key>Gauge</key>
<string>26</string>
<key>Thickness</key>
<string>1-3/8"</string>
<key>Insulated</key>
<string>Insulated</string>
<key>Material</key>
<string>Steel</string>
<key>Panel Design</key>
<string>Ribbed</string>
<key>Image</key>
<string>Steel-Craft TD-138</string>
</dict>
<key>TD-134</key>
<dict>
<key>Model</key>
<string>TD-134</string>
<key>Gauge</key>
<string>26</string>
<key>Thickness</key>
<string>1-3/4"</string>
<key>Insulated</key>
<string>Insulated</string>
<key>Material</key>
<string>Steel</string>
<key>Panel Design</key>
<string>Ribbed</string>
<key>Image</key>
<string>Steel-Craft TD-134</string>
</dict>
<key>SA-5000</key>
<dict>
<key>Model</key>
<string>SA-5000</string>
<key>Gauge</key>
<string>.071"</string>
<key>Thickness</key>
<string>1-3/4"</string>
<key>Insulated</key>
<string>Non-Insulated</string>
<key>Material</key>
<string>Aluminum</string>
<key>Panel Design</key>
<string>Full View</string>
<key>Image</key>
<string>No Image Available.jpg</string>
<key>Discontinued</key>
<true/>
</dict>
<key>SA-6000</key>
<dict>
<key>Model</key>
<string>SA-6000</string>
<key>Gauge</key>
<string>.071"</string>
<key>Thickness</key>
<string>1-3/4"</string>
<key>Insulated</key>
<string>Non-Insulated</string>
<key>Material</key>
<string>Aluminum</string>
<key>Panel Design</key>
<string>Polycarbonate</string>
<key>Image</key>
<string>Steel-Craft SA-6000.png</string>
</dict>
<key>SA-7000</key>
<dict>
<key>Model</key>
<string>SA-7000</string>
<key>Gauge</key>
<string>.071"</string>
<key>Thickness</key>
<string>1-3/4"</string>
<key>Insulated</key>
<string>Non-Insulated</string>
<key>Material</key>
<string>Aluminum</string>
<key>Panel Design</key>
<string>Full View</string>
<key>Image</key>
<string>Steel-Craft SA-7000.png</string>
</dict>
</dict>
</plist>
I have tried removing a model # by using:
Code:
[self.displayDoorDictionary removeObjectForKey:@"2400"];
I can however remove an entire manufacturer which is one of the primary keys, but I can't figure out how to remove a sub key (model #). Can anyone please help me.
|
If you read this structure from a plist, the container objects inside will not be mutable, even if they were when you saved the plist.
I've seen people write a mutableDeepCopy method that takes an immutable container object and recursively replaces all the objects inside that have mutable equivalents into mutable versions using mutableCopy.
Once you have a mutable dictionary of mutable dictionaries, you need to write code that fetches the dictionary from which you want to delete a key, and then delete the key from the child dictionary:
the2400Dict = [self.displayDoorDictionary objectForKey: @"2400"];
[the2400Dict removeObjectForKey: @"Model"];