Some of the code in a custom init method is not being called

Discussion in 'iOS Programming' started by moonman239, Jul 11, 2014.

  1. moonman239, Jul 11, 2014
    Last edited: Jul 11, 2014

    moonman239 macrumors 68000

    Joined:
    Mar 27, 2009
    #1
    I'm having a problem. A portion of a subclass's init code does not appear to be being called. The rest of the init method is called.
    Here is the code, straight from the relevant .m file:
    Code:
    -(id)init
    {
        self = [super init];
        if (self != nil) {
            NSURL *xmlURL = [[NSBundle mainBundle] URLForResource:@"exerciseInfo" withExtension:@"xml"];
            // Do some stuff that is related to the XML parser.
            xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
            [xmlParser setDelegate:self];
            [xmlParser parse];
            xmlElements = [[NSMutableArray alloc] init];  // There is a breakpoint here, but it never pauses when it is supposed to.  It's not set to be ignored at all, and "Automatically continue after evaluating" is not checked.
            unendedElements = [[NSMutableArray alloc] init];
        }
        return self;
    }
    
    Edit: The object in question is being initialized.
     
  2. plinden macrumors 68040

    plinden

    Joined:
    Apr 8, 2004
    #2
    What happens when you set a breakpoint earlier, e.g. at the [super init], and step through the code?
     
  3. moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #3
    Every line of code that I posted gets executed except the last two lines of code that are in the if block.
     
  4. mfram macrumors 65816

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #4
    I'm guessing that by calling "parse" the delegate functions in your class will be called. If those delegate functions are trying to use xmlElements and uneededElements they can't because they haven't been allocated yet.

    Maybe try moving the parse call after allocating those arrays.
     
  5. moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #5
    There was a breakpoint just before the } in the init method I posted, but that did not get called.

    Anyway, I am not looking for answers anymore.
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Then you should mark the thread Resolved.
     
  7. moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #7
    I chose not to mark the thread "Resolved" because I moved the last two lines of code to a different method instead of attempting to make the code be executed in the init method.
     
  8. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    I suggested marking the thread Resolved since you said you were no longer looking for answers to your query and thus others would not be tempted to provide further assistance. It's just a courtesy to those you seek help from.
     

Share This Page