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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:06:15+00:00 2026-05-26T14:06:15+00:00

I am trying to save/write an Array to the documents directory, and I am

  • 0

I am trying to save/write an Array to the documents directory, and I am completely stuck. I have checked this code with multiple sources online. I switched from and NSArray to a NSMutableArray and that didn’t work. From what I can tell is the file isn’t being written, because test is coming back null. Thanks in advance

NSArray *results = [parser objectWithData:data1];

NSMutableArray *array2 = [[NSMutableArray alloc] initWithArray:results];
// Create a dictionary from the JSON string  

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

//NSLog(@"the path is %@, the array is %@", path, array2);

/////write to file/////
[array2 writeToFile:path atomically:YES];

NSMutableArray *test = [[NSMutableArray alloc ]initWithContentsOfFile:path];

NSLog(@"the test is %@", test);

** update **

I added these lines of code

BOOL write = [results writeToFile:path atomically:YES];

NSLog(@"did it right? %@", write);

and write is null, what does that mean?

This is one of the many objects in my Array

{
     0 = "<null>";
    1 = "John Doe";
    10 = 512;
    11 = "<null>";
    12 = 1;
    13 = 1;
    2 = Doe;
    3 = Jon;
    4 = "<null>";
    5 = johndoe;
    6 = "<null>";
    7 = "<null>";
    8 = "john@doe.com";
    9 = "<null>";
    Type = 1;
    Active = 1;
    Depart = "<null>";
    Emp = "<null>";
    Ext = "<null>";
    FirstName = Jim;
    Fl = 512;
    Name = "John Doe";
    Log = jd;
    Mobile = "<null>";
    Title = "<null>";
}

Do the null values have anything to do with it?

SOLVED!!

I realized that the null values may have been causing some issues, so i changed my query to take care of that and it saved instantly. The above code is 100% correct and it works!

thanks for the help

  • 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-26T14:06:16+00:00Added an answer on May 26, 2026 at 2:06 pm

    As per the documentation, writeToFile: only works if your array’s contents are limited to a handful of types (NSString, NSData, NSArray, or NSDictionary objects). If you have any other type of object in your array, then it will not write to file correctly (or at all).

    Note also that writeToFile: returns a boolean value indicating whether or not the operation succeeded.

    If your array contains incompatible types, you will have to look at using something like NSKeyedArchiver to serialize your data instead.

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

Sidebar

Related Questions

I am trying to write save as dialog with javascript, I have a content
I'm trying to save a PDF file to SQL Server and I already have
I am trying to save images using the following code: - (void)writeData{ if(cacheFileName==nil) return;
I am trying to write a ruby function that iterates through an array of
I'm trying to write cookie after logging in but it doesn't seem to save
I have an asp.net app and I am trying to save a text file
I am trying to write a simple method to save my document to a
I'm trying to write on xml file. but my server have DOM as disabled.
I'm trying to write an array (list?) to a text file using Python 3.
I’m trying to save an array to a .plist file on my iphone but

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.