Memory allocation problem

Discussion in 'iOS Programming' started by Sergio10, Sep 22, 2009.

  1. Sergio10 macrumors regular

    Joined:
    Oct 3, 2007
    #1
    Hi,

    According to string I'd like to create new string but it crashes:
    PHP:
    - (NSString*)test
    {
        switch (
    self.type
        {
            case 
    SHIPMENT_LIST_XML:
            {
                
    NSString *xml = [[NSString allocinitWithString:[parser nodeValue:PARAM_1]];
                
                if(
    xml == nil)
                {
                    return 
    nil;
                }
                else
                {
                    [
    parser deleteNode:PARAM_1];
                    
                    return 
    xml;
                }
            } break;
        }
        return 
    nil;
    }
    Do I create xml value correctly?

    Thank you,
    Serhiy Otroshchenko
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Crashes how? Are there run-time errors? Specifics would be a big help.
     
  3. Darkroom Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #3
    i believe switch statements can only receive integers as arguments. try using if.
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    No, they can be simple constants or constant expressions. The problem is the OP's code snippet is too vague to draw any conclusions about things like this and therefore very hard to diagnose why it doesn't work. That's why I asked for more specifics.
     
  5. Darkroom Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #5
    good to know :)
     

Share This Page