comparing values from a plist

Discussion in 'iOS Programming' started by MrCrispy, Apr 8, 2010.

  1. MrCrispy macrumors member

    MrCrispy

    Joined:
    Apr 10, 2008
    Location:
    Jacksonville, Florida
    #1
    I'm storing 2 strings in a plist for preferences. When I try to pull the values out and use them in a comparison, they don't seem to be working. No matter what the values it keeps popping to the else block. I have a feeling I'm missing something obvious (been a long day).

    Code:
    		NSArray *values = [[NSArray alloc] initWithContentsOfFile:myPath]; //loads plist
    
    //dirty way of converting string to bool
    		if ([values objectAtIndex:0] == @"YES") {
    			paid.on = YES;
    		}	else {
    			paid.on = NO;
    		}
    
    
    		NSLog([values objectAtIndex:1]); //make sure I'm not crazy and pulling the wrong value
    
    //Quick note: just using == 8 didn't work either.
    		if ([values objectAtIndex:1] == @"8") {
    			switchInternal.selectedSegmentIndex = 0;
    		} else {
    			switchInternal.selectedSegmentIndex = 1;
    		}
    
    Here is the structure of the plist:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <array>
    	<string>YES</string>
    	<string>8</string>
    </array>
    </plist>
    
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    == is not the proper way to compare strings. Check NSString's instance methods for a better way.
     
  3. MrCrispy thread starter macrumors member

    MrCrispy

    Joined:
    Apr 10, 2008
    Location:
    Jacksonville, Florida
    #3
    gah! My c# was creeping in. This is why I shouldn't program after my bedtime. Thanks!
     

Share This Page