0

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?

Jesus Ramos
  • 22,940
  • 10
  • 58
  • 88
Josh Elias
  • 3,250
  • 7
  • 42
  • 73

2 Answers2

2

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];
Jeffery Thomas
  • 42,202
  • 8
  • 92
  • 117
0

Like said in the comments, you will have to wrap TBXMLElement* in a subclass of NSObject. Probably something like:

@interface MyXMLElement {
TBXMLElement* _xmlElement;
}

-(void)setXMElement:(TBXMLelement*)element;

@end

You can then populate the element:

MyXMLElement *elmt = [[MyXMLElement alloc] init];

[emlt setXMLElement:pointerToTBXMLElement];

[someArray addObject:elmt];
Mike D
  • 4,938
  • 6
  • 43
  • 99