Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8347099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:15:12+00:00 2026-06-09T07:15:12+00:00

Possible Duplicate: How to write to plist successfully? I want to simply write the

  • 0

Possible Duplicate:
How to write to plist successfully?

I want to simply write the boolean state of a UISwitch(true or false) in a Plist file.

Here is what I already got, but the values do not change in the plist:

.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController {


    IBOutlet UISwitch *mySwitch;

}

-(IBAction)changeThingsInPlist:(id)sender;

@end

.m

#import "ViewController.h"

BOOL changeThing;
#define PLIST_PATH @"/var/mobile/Library/Preferences/com.myname.plistname.plist"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];


    changeThing = [[[NSDictionary dictionaryWithContentsOfFile:PLIST_PATH]valueForKey:@"changeThing"]boolValue];

}

-(IBAction)changeThingsInPlist:(id)sender {

    if (mySwitch.on = YES) {
        changeThing = true;
    }
    else {
        changeThing = false;
    }
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end

I simply want to change the value(true or false) in the plist file by switching the uiswitch.

should I use NSUserDefaults? 🙂

I read into it, but I never got, how to set the plist path in the NSUserDefaults

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T07:15:14+00:00Added an answer on June 9, 2026 at 7:15 am

    I would say that you should create an NSString and set the value of it based on the boolean value of the UISwitch.

    NSString *valueOfSwitch;
    if (mySwitch.on == YES){
    valueOfSwitch = [NSString stringWithFormat:@"ON"];
    }
    else {
    valueOfSwitch = [NSString stringWithFormat:@"OFF"];
    }
    

    Then you should put that string in the NSUserDefaults like so.

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:valueOfSwitch forKey:@"switchValue"];   //remember this for retrieving
    [defaults synchronize];
    

    Then to retrieve this string you do this.

    NSUserDefaults *data = [NSUserDefaults standardUserDefaults];
    NSString *switchString = [data objectForKey:@"switchValue"]; //same key that you used for saving
    [data synchronize];
    

    From there you can do whatever you want with that string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to write a UTF-8 file with Java? I want to create
Possible Duplicate: How to write to plist successfully? i m trying to write to
Possible Duplicate: using bash: write bit representation of integer to file I need to
Possible Duplicate: Read/write .txt file with special characters Im reading a file but I
Possible Duplicate: Detecting SMS incoming and outgoing I want to write a app that
Possible Duplicate: read/write to Windows Registry using Java I want to read the registry
Possible Duplicate: Is it possible to write to a file (on a disk) using
Possible Duplicate: Obtaining const_iterator from iterator I want to write a metafunction which returns
Possible Duplicate: Find location of current m-file in Matlab I would like to write
Possible Duplicate: Writing into a file objective c How do I create and write

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.