Parser implementation with NSXMLParser

Discussion in 'iOS Programming' started by vilelam, Feb 20, 2011.

  1. vilelam, Feb 20, 2011
    Last edited by a moderator: Feb 20, 2011

    vilelam macrumors newbie

    Joined:
    Feb 20, 2011
    #1
    Hi Experts,
    I'm trying to figure out whats wrong with this code, it returns an error while its running. I'm trying to implement a parser using NSXMLParser class.
    The error is: "[ParseXML setCurrentProperty:]: unrecognized selector sent to instance 0x100112e70" and it happens into the delegate method bellow:

    Code:
    - (void) parser : (NSXMLParser *)parser didStartElement : (NSString *)elementName 
             namespaceURI : (NSString *)namespaceURI qualifiedName : (NSString *)qName 
             attributes : (NSDictionary *)attributeDict {
    
        if ( [elementName isEqualToString:@"lastName"] ) {
            
            [COLOR="DarkRed"][self setCurrentProperty:kABLastNameProperty];[/COLOR]
            return;
        
        }
    }


    I'm importing AddressBook framework but it seems that the method setCurrentProperty is no available into my class. Any help will be appreciated.

    Thanks,
    Marcos Vilela.
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    What is self? Does it have a setCurrentProperty: instance method?
     
  3. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #3
    Couldn't agree more.
    Do u have a currentProperty assigned there. Or is it a method ;)
    Did u synthesize the property, so it actually does have getters/setters u can acces? :)

    Those are the things to figure it out.
     
  4. vilelam thread starter macrumors newbie

    Joined:
    Feb 20, 2011
    #4
    Dejo and Jnoxx,
    thanks for the answers.

    I didn't create any method called setCurrentProperty, but I'm importing Address Book Framework into my class.


    To implement this code, I`m following a guide from Apple (Event-driven XML programming guide) and from the guide I got this information:

    [self setCurrentProperty:kABLastNameProperty] -> Sets an instance variable holding the current Address Book property; this value is a enum constant declared in the Address Book framework.

    Is it enought to #import address book framework? In my opinion, it seems that my class need to extend another class with this method (setCurrentProperty).


    Any help?


    Thanks,
    Marcos Vilela.
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    Almost certainly not. Can you tell us more about what you're trying to achieve? You're parsing an XML document, that much we know. But then what are you doing with the data from that XML? What is the object whose current property you are hoping to update? Think about these things some more and perhaps the issues with your code will become clearer.

    Also, what is your comfort level with Objective-C / iPhone programming? What have you done to educate yourself on the basic fundamentals? And please: be specific. "I read a book" or "I took some online tutorials" are too vague.
     
  6. vilelam thread starter macrumors newbie

    Joined:
    Feb 20, 2011
    #6
    Hi Dejo,
    I Solved the problem implementing the setCurrentProperty method as you told in the first reply. Very easy...

    @property (nonatomic, copy) NSString *currentProperty;
    @synthesize currentProperty;

    Aswering your question, I'm new to objective C and trying to learn the syntax coding this XMLParser. I've never read a book... just did a hello world before this parser.. lol..

    Thanks and regards,
    Marcos Vilela.
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    Then I would suggest you step away from the real coding and go learn the basics of Objective-C / iPhone programming. It will help if you learn to walk before you run. Probably wouldn't hurt to check out the Guides and Stickies at the top of this very forum either.
     

Share This Page