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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:39:28+00:00 2026-05-24T20:39:28+00:00

I have 4 NSMutableArray, and on launch they are properly initialized. In a section

  • 0

I have 4 NSMutableArray, and on launch they are properly initialized. In a section of my code, I write the contents of these arrays to individual plist files, and these plist files have been created and added to the project. I have 4 instances of writing to file, and for some reason only the first 2 write to file successfully (didWrite and didWrite2) but didWrite3 and didWrite 4 return “nope” all the time meaning an unsuccessful write. Here is the code that initializes and allocates the arrays in applicationDidFinishLaunching:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *DataPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Data.plist"];
    NSString *inkDatesPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"inkDates.plist"];
    NSString *inkFontPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"inkFont.plist"];
    NSString *inkColorPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"inkColor.plist"];
    NSFileManager *fileManager = [NSFileManager defaultManager];

    if (![fileManager fileExistsAtPath: DataPath])
    {
        inks=[[NSMutableArray alloc] init ];
         NSLog(@"initialized inks as new");
    }
    else inks=[[NSMutableArray alloc] initWithContentsOfFile:DataPath];

    if (![fileManager fileExistsAtPath: inkDatesPath])
    {
        inkDates=[[NSMutableArray alloc] init ];
    }
    else inkDates=[[NSMutableArray alloc] initWithContentsOfFile:inkDatesPath];

    if (![fileManager fileExistsAtPath: inkFontPath])
    {
        inkFont=[[NSMutableArray alloc] init ];
    }
    else inkFont=[[NSMutableArray alloc] initWithContentsOfFile:inkFontPath];

    if (![fileManager fileExistsAtPath: inkColorPath])
    {
        inkColor=[[NSMutableArray alloc] init ];
        NSLog(@"initialized inkColor as new");
    }
    else { 
        inkColor=[[NSMutableArray alloc] initWithContentsOfFile:inkColorPath];
        NSLog(@"initialized inkColor as copy");

When the app is first launched, I get “initialized inkColor as new”, but I still get a fail to write. inks and inkDates write properly but the other two dont. And here is my code that tries to write to the plist files:

  NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1
    NSString *documentsDirectory = [paths objectAtIndex:0]; //2


    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"Data.plist"]; //3
    NSFileManager *fileManager = [NSFileManager defaultManager];

    if (![fileManager fileExistsAtPath: path])
    {
        NSString *bundle=[[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"];
        [fileManager copyItemAtPath:bundle toPath: path error:&error]; //6
    }

    NSString *pathDates = [documentsDirectory stringByAppendingPathComponent:@"inkDates.plist"]; //3
    NSFileManager *fileManagerDates = [NSFileManager defaultManager];

    if (![fileManagerDates fileExistsAtPath: pathDates])
    {
        NSString *bundle=[[NSBundle mainBundle] pathForResource:@"inkDates" ofType:@"plist"];
        [fileManagerDates copyItemAtPath:bundle toPath: pathDates error:&error]; //6
    }

    NSFileManager *fileManagerFont = [NSFileManager defaultManager];
    NSString *pathFont = [documentsDirectory stringByAppendingPathComponent:@"inkFont.plist"];
    if (![fileManagerFont fileExistsAtPath: pathFont])
    {
        NSString *bundle=[[NSBundle mainBundle] pathForResource:@"inkFont" ofType:@"plist"];
        [fileManagerFont copyItemAtPath:bundle toPath: pathFont error:&error]; //6
    }

    NSFileManager *fileManagerColor = [NSFileManager defaultManager];
    NSString *pathColor = [documentsDirectory stringByAppendingPathComponent:@"inkColor.plist"];
    if (![fileManagerFont fileExistsAtPath: pathColor])
    {
        NSString *bundle=[[NSBundle mainBundle] pathForResource:@"inkColor" ofType:@"plist"];
        [fileManagerColor copyItemAtPath:bundle toPath: pathColor error:&error]; //6
    }


    NSDate *date = [NSDate date];
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"EEEE, MMMM d, YYYY"];
    NSString *dateString = [dateFormat stringFromDate:date];  
    [dateFormat release];

            [appDelegate.inks addObject:[inkTextField text]];
            [appDelegate.inkDates addObject:dateString];
            [appDelegate.inkFont addObject:[inkTextField font]];
            [appDelegate.inkColor addObject:[inkTextField textColor]];
            NSLog(@"inkColor count: %i", [appDelegate.inkColor count]);
            NSLog(@"Wrote to new index");

    BOOL didWrite=[appDelegate.inks writeToFile: path atomically:YES];
    if(didWrite==YES)
       NSLog(@"didWrite");
    else NSLog(@"nope");



    BOOL didWrite2;
    didWrite2=[appDelegate.inkDates writeToFile: pathDates atomically:YES];
    if(didWrite2==YES)
        NSLog(@"didWrite");
    else NSLog(@"nope");


    BOOL didWrite3;
    didWrite3=[appDelegate.inkFont writeToFile: pathFont atomically:YES];
    if(didWrite3==YES)
        NSLog(@"didWrite");
    else NSLog(@"nope");

    BOOL didWrite4;
    didWrite4=[appDelegate.inkColor writeToFile: pathColor atomically:YES];
    if(didWrite4==YES)
        NSLog(@"didWrite");
    else NSLog(@"nope");
  • 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-24T20:39:29+00:00Added an answer on May 24, 2026 at 8:39 pm

    You are using writeToFile which attempts to write proper plists. Its documentation states:

    This method recursively validates that all the contained objects are
    property list objects (instances of NSData, NSDate, NSNumber,
    NSString, NSArray, or NSDictionary) before writing out the file, and
    returns NO if all the objects are not property list objects, since the
    resultant file would not be a valid property list.

    If the dictionary’s contents are all property list objects, the file
    written by this method can be used to initialize a new dictionary with
    the class method dictionaryWithContentsOfFile: or the instance method
    initWithContentsOfFile:.

    UIColor and UIFont are not in the list.

    Generally you might want to use the NSCoding protocol (using NSCoder objects) instead which allows you to serialize data more effectively. However, even then there is no good way to store UIFont objects – they don’t conform to NSCoding and cannot be serialized. You should store the font family/size and then have custom code to restore the font when loading the data.

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

Sidebar

Related Questions

I have this code: tableList = [[NSMutableArray alloc] initWithObjects:@First View,@Second View,nil]; I have synthesized
I have a NSMutableArray I get by loading a plist into it. The date
I have an NSMutableArray with contents I want to replace with NSNull objects. This
I have a NSMutableArray which i am initializing from a plist with strings. but
I have a NSMutableArray which repeatedly will be filled with the changing contents of
I have NSMutableArray containing UIImageViews and NSArray containing UIImages. The arrays are of equal
This is what I have NSMutableArray Code = [COMM 112, MATH 101, SCI 201];
I have a NSMutableArray: NSMutableArray *temp = //get list from somewhere. Now there is
I have an NSMutableArray that is populated with objects of strings. For simplicity sake
I have a NSMutableArray that I need to search for a string and return

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.