How do you form if statements, -> if variable is set?

Discussion in 'iOS Programming' started by ct2k7, Jan 23, 2010.

  1. ct2k7 macrumors 603

    ct2k7

    Joined:
    Aug 29, 2008
    Location:
    London or Florida
    #1
    Hi, how do I properly form this if statement?

    Code:
    [COLOR=#000000][COLOR=#666666][I] if (!selectedCell) { 
      NSString *urlAddress = @"[URL]http://www.google.com[/URL]";}
     else {
      NSString *urlAddress =[[NSBundle mainBundle] pathForResource:@"selectedCell" ofType:@"htm"];}[/I][/COLOR][/COLOR]
    
    Thanks;)
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    The form of your if statement looks fine. What seems to be your issue with it?
     
  3. ct2k7 thread starter macrumors 603

    ct2k7

    Joined:
    Aug 29, 2008
    Location:
    London or Florida
    #3
    SDK complains that *urladdress is not being set :(
     
  4. skunkworker macrumors regular

    Joined:
    Sep 9, 2007
    #4
    keep in mind there is a scope for variables. Once you have allocated & initialized those strings than they are freed. You need to created the urlAddress outside of the if and else command.

    Code:
     
    NSString *urlAddress = [NSString string];
    
     if (!selectedCell) { 
      urlAddress = @"http://www.google.com";}
     else {
      urlAddress =[[NSBundle mainBundle] pathForResource:@"selectedCell" ofType:@"htm"];}
    
     
  5. ct2k7 thread starter macrumors 603

    ct2k7

    Joined:
    Aug 29, 2008
    Location:
    London or Florida

Share This Page