Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 622295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:58:10+00:00 2026-05-13T18:58:10+00:00

I noticed that when I do this : [myParser setDelegate:self]; it works :D (even

  • 0

I noticed that when I do this :

[myParser setDelegate:self];

it works 😀 (even if I didn’t add the code in the header file … you know, the

<delegateStuff, delegateOtherStuff> 

in the interface declaration)

When are you supposed to modify the header file to make your delegate work ? Is the setDelegate method enough to make it work ?

Cheers for any help 😉

Gauthier

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:58:10+00:00Added an answer on May 13, 2026 at 6:58 pm

    In short, the <NSXMLParserDelegate> in your interface declaration is not required, it’s there for error checking at compile time. Calling the setDelegate: method is required if you want to receive delegate messages.

    The <delegateStuff> you refer to are protocol declarations. A Protocol in Objective-C is like an Interface in Java: it defines a list of messages (methods) that the class responds to. Unlike Java, however, Objective-C is dynamically typed, meaning any message can be sent to any object and you can only be sure if it will respond to it at run time.

    The upshot of this is that if a method like setDelegate: asks for a parameter of type id, you can give it any object whatsoever. The code in NSXMLParser can check if it is able to respond to a specific message before sending it. That way you can implement whatever delegate methods you want. (Because Java has more strict type checking, you must implement all the methods in an interface, whether you need them all or not.)

    If setDelegate: instead act for a type id <NSXMLParserDelegate> it is now saying that it wants an object that implements the NSXMLParserDelegate protocol. This is only checked at compile time to help you catch errors, though. If you use a typecast you can send any object in there and, as long as it responds to the required messages, your program will run fine. (Again, in Java, you could use a typecast to compile, but the typecast itself would throw an exception if the object wasn’t of the correct type, even if it had the same methods.)

    By the way, are you subclassing NSXMLParser? (I assume so, since you are passing self to setDelegate:. That is not the way it is meant to be used! The Cocoa frameworks usually prefer delegates over subclasses. Your delegate class should be a separate class extending NSObject (or something else if you want).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was playing around with some Javascript snippets today and noticed that this code
I noticed that Feedzirra uses this regex to get the ETag from response header:
Looking at the JDK source code for LinkedHashMap, I noticed that this class is
While reading the source code of SortableIntField , I noticed that this class avoids
I noticed that this code compiles but I have no idea why: int main()
I noticed that this recipe seems to use __rlshift__ , __ror__ like operators. But,
I've noticed that running this subquery SELECT ST_Area(ST_Union(ST_Transform(ST_Intersection((SELECT poly1.the_geom from poly1 WHERE poly1.polygon_type='P'),poly2.the_geom),3857))) AS
I 've researched and noticed that ActiveResource lack this functionality. So, what is the
I noticed that some stylesheets have something like this: body { font-size: 62.5%/1.2em; }
While reading this class BitmapFactory I noticed that almost all methods inside are static.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.