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 6933175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:47:55+00:00 2026-05-27T11:47:55+00:00

I have a .plist created at the application launch with the following code (MyAppTableViewController):

  • 0

I have a .plist created at the application launch with the following code (MyAppTableViewController):

NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *finalPath = [documentsDirectory stringByAppendingPathComponent:@"Settings.plist"];

BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:finalPath];

if (!fileExists) {
    NSLog(@"Creating file");
    NSDictionary *plistDict = [[NSDictionary alloc]initWithObjectsAndKeys:@"1",@"Fade out",@"1",@"Enable Gestures",@"1",@"Proximity Sensor",@"1",@"Keep screen ON",nil];
    NSString *error = nil;

    NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:plistDict format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];

    if(plistDict) {
        [plistData writeToFile:finalPath atomically:YES];
    } else {
        NSLog(@"Error: %@", error);
        [error release];
    }
}

This works fine and the file is created with keys and values. I then have a table with four switches with a function toggle: as the selector.

The code inside -(void)toggle:(id)sender takes the switch’s value along with the row of the indexPath and modifies the plist accordingly:

-(void)toggle:(id)sender {
    UISwitch *aSwitch = (UISwitch *)sender;
    UITableViewCell *cell = (UITableViewCell *)aSwitch.superview;
    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];    

    NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *finalPath = [documentsDirectory stringByAppendingPathComponent:@"Settings.plist"];
    NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithContentsOfFile:finalPath];

    if (indexPath.section == 0 && indexPath.row == 0) {
        [dictionary setObject:[NSNumber numberWithBool:aSwitch.on] forKey:@"Fade out"];
    }
//There are further (similar) else if statements, but I'll leave them out.

    NSString *error = nil;
    NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:dictionary format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];

    if(dictionary) {
        [plistData writeToFile:finalPath atomically:YES];
    } else {
        NSLog(@"Error: %@", error);
        [error release];
    }
}

This is also working fine and modifies the plist successfully. My issue arises when I try to to retrieve the data with the following code:

NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *finalPath = [documentsDirectory stringByAppendingPathComponent:@"Settings.plist"];
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithContentsOfFile:finalPath];

fadeOut = [[NSString stringWithFormat:[dictionary objectForKey:@"Fade out"]]boolValue];
proximitySensor = [[NSString stringWithFormat:[dictionary objectForKey:@"Proximity Sensor"]]boolValue];
enableGestures = [[NSString stringWithFormat:[dictionary objectForKey:@"Enable Gestures"]]boolValue];
keepScreenOn = [[NSString stringWithFormat:[dictionary objectForKey:@"Keep screen ON"]]boolValue];

In the declaration file, I have defined BOOL fadeOut,proximitySensor,enableGestures,keepScreenOn;. Grabbing the information works fine, but it’s when I change the BOOL values, the application crashes. I can’t quite understand what the problem is. Perhaps I’m missing the bigger picture or a simple but important mistake with Boolean values.

If I remove the above code, everything works fine. But If I leave it there, the app crashes with the following message:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFBoolean length]: unrecognized selector sent to instance 0x3f39a9f0'

Help is much appreciated!

  • 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-05-27T11:47:56+00:00Added an answer on May 27, 2026 at 11:47 am

    If you look at this line

    fadeOut = [[NSString stringWithFormat:[dictionary objectForKey:@"Fade out"]]boolValue]
    

    You’re initializing a string from an NSNumber (you stored you BOOL in a NSNumber). That’s invalid by itself.

    If you need an bool value of an NSNumber, use simply boolValue on it.

    fadeOut = [[dictionary objectForKey:@"Fade out"] boolValue];
    

    That’s true for all the time you’re retrieving the boolean value.

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

Sidebar

Related Questions

I am developing an application where i have created the plist, and i am
I have an application in Xcode 4.2. I have created plist file as my
I have successfully created an app that reads from a bundled .plist file and
I have a settings bundle in my iPhone app, with the following PList: Type:
I'm using a NSDictionary to get a NSString from a plist with the following
have developed an application for my clients, in the info.plist i have : bundle
I have an application that was originally created compatible with iOS 2.x. With Xcode
I have created a static library for my application. Now, my application uses sources
I have created save.plist in a resource folder. I have written some data within
I have created a split view application that begins with a modal view splash

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.