1

I need help trying to do a crude type of confirmation where you need to type: I got it! into a NSTextField then press button1 so that once they do press button1 I make my button2 enabled using

 -(IBAction)check:(id)sender{
    NSString *string = [NSString stringWithValue:@"I Got It!"];
    if(field.stringValue isEqualToString:string){
      [field setHidden:YES];
      [button1 setHidden:YES];
      [button2 setEnabled:YES]
    }
  }

This is only a one-time confirmation so I'm wondering how I can save the state of the button so that next time they launch the app they don't have to do the confirmation again. The textfield and button1 will be hidden and so that button2 will always be enabled, I want to use the NSUserDefaults because I think that would be the easiest for me to understand.

Jeffrey Bosboom
  • 13,313
  • 16
  • 79
  • 92
cyw
  • 520
  • 1
  • 4
  • 14

2 Answers2

1

Have a look at NSUserDefaults Class Reference. You can use - (void)setBool:(BOOL)value forKey:(NSString *)defaultName

Parag Bafna
  • 22,812
  • 8
  • 71
  • 144
1

You can use as below

if ([[NSUserDefaults standardUserDefaults] boolForKey:@"ishidden"] != YES){

// First launch

} else { //not first launch }

Dipen Patel
  • 911
  • 2
  • 9
  • 22