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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:40:46+00:00 2026-06-08T15:40:46+00:00

I have in my code an array of custom objects. i want to write

  • 0

I have in my code an array of custom objects.

i want to write this array in a file on the documents folder. in this answer iPhone – archiving array of custom objects i saw that i need to implement this methods:

- (void)encodeWithCoder:(NSCoder *)aCoder;
- (id)initWithCoder:(NSCoder *)aDecoder;

so i implemented them:

- (void)encodeWithCoder:(NSCoder *)encoder {
  [encoder encodeObject:self.data forKey:@"data"];
  [encoder encodeObject:self.nome forKey:@"nome"];
  [encoder encodeObject:self.celular forKey:@"celular"];
  [encoder encodeObject:self.endereco forKey:@"endereco"];
  [encoder encodeObject:self.horaConclusao forKey:@"horaConclusao"];
  [encoder encodeObject:self.horaAtendimento forKey:@"horaAtendimento"];
}

- (id)initWithCoder:(NSCoder *)decoder {
  self = [super init];
  if (self) {
    self.data = [decoder decodeObjectForKey:@"data"];
    self.nome = [decoder decodeObjectForKey:@"nome"];
    self.celular = [decoder decodeObjectForKey:@"celular"];
    self.endereco = [decoder decodeObjectForKey:@"endereco"];
    self.horaConclusao = [decoder decodeObjectForKey:@"horaConclusao"];
    self.horaAtendimento = [decoder decodeObjectForKey:@"horaAtendimento"];
  }

  return self;
}

and in my code i write using this method:

this code is to remove old files

-(NSString *) plistHistoryFile {
  NSError *error;
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  NSString *documentsDirectory = [paths objectAtIndex:0];
  NSString *path = [documentsDirectory stringByAppendingPathComponent:[nameFile stringByAppendingPathExtension:@"plist"]];

  NSFileManager *filemgr = [NSFileManager defaultManager];
  if ([filemgr fileExistsAtPath:path]) {
    [filemgr removeItemAtPath:path error:&error];
  }

  return path;
}

and i call the write in this method:

-(void) writeArrayToHistoryFile:(NSArray *) array {
  NSString *path = [self plistHistoryFile];
  NSLog(@"%@", path);

  if ([array writeToFile:path atomically:NO]) {
    NSLog(@"YES");
  } else {
    NSLog(@"NO");
  }
}

but my response on the log is always NO, what am i doing wrong?

  • 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-08T15:40:50+00:00Added an answer on June 8, 2026 at 3:40 pm

    You need to find out what the error is, but you can’t get the error using -[NSArray writeToFile:atomically:]. Instead, write the file this way:

    NSError *error;
    
    NSData *data = [NSPropertyListSerialization dataWithPropertyList:array
        format: NSPropertyListBinaryFormat_v1_0 options:0 error:&error];
    if (!data) {
        NSLog(@"failed to convert array to data: %@", error);
        return;
    }
    
    if (![data writeToFile:path options:NSDataWritingAtomic error:&error]) {
        NSLog(@"failed to write data to file: %@", error);
        return;
    }
    
    NSLog(@"wrote data successfully");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code to sort an array of objects. The data in the
so i have an array of custom objects. i want to go through them
I have this code: var a:Array = [ Ramsey, Tusey, Iuser,Sephora,'user', 'reseo', 'nesey', 'sela']
I have this php code $jsonArray = array(); $sql = SELECT ID,CLIENT FROM PLD_SERVERS;
i have this code that will check the array contains the specific string and
I have these code in my views.py: array = [] p = Person.objects.filter(client=1,status='Complete').values('name', 'age',
I have an array of objects which created from a custom class. The custom
I have an array myArr which contains objects of custom class..e.g. objs of type
I have an array of objects and I want to concatenate it with another
i have an array list of custom objects. each object contains a value i

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.