iosxmltbxml

Copy C pointers to NSMutableDictionary


I have a class that parses through an XML file in iOS.

You can get the data of an element in the form of an TBXMLElement*.

I want to iterate through the XML and make deep copies of the TBXMLElements and store them in an NSMutableDictionary class variable.

How can I:

myClassDict addObject:(TBXMLElement*)element?


Solution

  • You can put the pointers in an NSValue. What key are you going to use?

    // Save the TBXMLElement*
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:[NSValue valueWithPointer:element] forKey:@"whatKey"];
    
    …
    
    // Get the TBXMLElement*
    TBXMLElement *el = (TBXMLElement *)[[dict valueForKey:@"whatKey"] pointerValue];