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

  • Home
  • SEARCH
  • 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 6625621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:47:46+00:00 2026-05-25T21:47:46+00:00

I’m working through the NSXMLParser sample code and I have a couple of questions

  • 0

I’m working through the NSXMLParser sample code and I have a couple of questions about how delegates and properties are set, particularly in the AppDelegate.

In the interface, the AppDelegate is declared to follow the NSXMLParserDelegate protocol, but it doesn’t seem to implement any of the protocol methods or to set itself as the delegate at any point. These seem to be in the ParseOperation class. Is this just a typo?

@interface SeismicXMLAppDelegate : NSObject <UIApplicationDelegate, NSXMLParserDelegate> {
    UIWindow *window;
    UINavigationController *navigationController;
    RootViewController *rootViewController;

@private
    // for downloading the xml data
    NSURLConnection *earthquakeFeedConnection;
    NSMutableData *earthquakeData;

    NSOperationQueue *parseQueue;
}

The interface also declares some private properties. These are defined again in an interface extension in the .m file.

@interface SeismicXMLAppDelegate ()

@property (nonatomic, retain) NSURLConnection *earthquakeFeedConnection;
@property (nonatomic, retain) NSMutableData *earthquakeData;    // the data returned from the NSURLConnection
@property (nonatomic, retain) NSOperationQueue *parseQueue;     // the queue that manages our NSOperation for parsing earthquake data

- (void)addEarthquakesToList:(NSArray *)earthquakes;
- (void)handleError:(NSError *)error;
@end

OK, I think I understand that this means other classes can’t access these properties, and that seems like a really good thing in this case. Here’s the mystery – In the implementation of –applicationDidFinishLaunching: the two properties are defined using different notations.

self.earthquakeFeedConnection =
[[[NSURLConnection alloc] initWithRequest:earthquakeURLRequest delegate:self] autorelease];

vs

parseQueue = [NSOperationQueue new];

Why is one assigned using self.propertyName = and the other with propertyName = ? I know that both parseQueue and earthquakeFeedConnection end up with retain counts of 1, with the difference that earthquakeFeedConnection is part of the autorelease pool and will be released automatically whereas we’ll have to release parseQueue later because of the use of +new and not calling autorelease.

The memory considerations don’t explain the use of self. Is there another difference?

  • 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-25T21:47:47+00:00Added an answer on May 25, 2026 at 9:47 pm

    alloc and new return objects which are retained once. init have no effect on memory-management and autorelease will release that object later once.

    if you write self.myProperty = ... then the synthesized setter is called which behaves like you defined in the according property nonatomic, retain. The nonatomic means that the getter and setter are not threadsafe (but fast). retain means in this case that the setter will release the old object and will retain the new object. if you wrote assign instead of retain the setter would just assign the pointer and wouldn’t call release or retain on the affected objects.

    The goal in your example is to create two objects which are retained once.
    Example1:

    self.earthquakeFeedConnection = [[[NSURLConnection alloc] initWithRequest:earthquakeURLRequest delegate:self] autorelease];
    
    • after alloc: retainCount: 1
    • after autorelease: retainCount: 1-1 (minus one means: released later)
    • after calling the setter: retainCount: 2-1

    Exmaple 2:

    parseQueue = [NSOperationQueue new];

    • after new: retainCount: 1

    So in the end both cases result in the same. you could also write

    earthquakeFeedConnection = [[NSURLConnection alloc] initWithRequest:earthquakeURLRequest delegate:self];
    

    The setter-solution looks more complicated but there are some side-effects. If you notice later that you need special behaviour inside either the getter or setter (for instance: triggering some other methods or do some value-checking: NSString which only should contains eMail-Addresses) then you only have to overwrite the getter or setter. If you dont use self.myProp = ... then you have to search for usage and have to change that code-snippet as well.

    The delegate-stuff: yes, you are right: normally you have to (or should) list alle implemented protocols in the interface-definition but the NSURLConnectionDelegate is an exception. I dont know why (I dont find the implementation-point in NSObject-class-reference) but every NSObject implements that delegate already. So as a result you dont have to mention that your class is implementing that delegate.

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

Sidebar

Related Questions

I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

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.