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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:25:11+00:00 2026-06-10T13:25:11+00:00

first of all, I have a class which mamages an NSMutableArray. When the class

  • 0

first of all, I have a class which mamages an NSMutableArray.
When the class is instantiated, it should look if there is already a saved array and load it, or otherwise made a new one.

everytime an item is added it should be saved. but: nothing happens.

#import "NEList.h"

@interface NEList()



@end

@implementation NEList
@synthesize theInternArray;



-(id) initWithArray {
    self = [super init];

    if(self != nil) {
             NSLog(@"build");

        theInternArray = [[NSMutableArray alloc] initWithCapacity:20];

        return self;
    }
    return nil;
}

-(id) initWithContent {
    self = [super init];

    if(self != nil) {
        NSLog(@"load");

        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"theFiles"];

        theInternArray = [NSMutableArray arrayWithContentsOfFile:filePath];

        if(theInternArray == nil) {
            theInternArray = [[NSMutableArray alloc] initWithCapacity:200];
        }
               NSLog(@"second %@", theInternArray);
        return self;
    }
    return nil;
}

-(BOOL) save {

   NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  NSString *documentsDirectory = [paths objectAtIndex:0];
   NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"theFiles"];


    return [self.theInternArray writeToFile:filePath atomically:NO];
}

-(BOOL) addObject:(NEListItem *)theItem {

    [theInternArray addObject:theItem];    [self save];





    UILocalNotification *localNotif = [[UILocalNotification alloc] init];

    localNotif.fireDate = theItem.theBestBeforeDate;
    localNotif.timeZone = [NSTimeZone defaultTimeZone];

    localNotif.alertBody = [theItem.theName stringByAppendingString:@" expires!"];
    localNotif.alertAction = NSLocalizedString(@"View Details", nil);

    localNotif.soundName = UILocalNotificationDefaultSoundName;
    localNotif.applicationIconBadgeNumber = 1;



    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];


    return true;
}


-(NEListItem *) getElementAtIndex:(NSUInteger)theIndex {
    return [theInternArray objectAtIndex:theIndex];
}

-(BOOL)removeObjectByName:(NSString *)theName {

    for (NEListItem *tempItem in theInternArray) {

        if([tempItem.theName isEqualToString:theName]) {
            [theInternArray removeObject:tempItem];
            break;
            return true;
            }
    }

            NSLog(@"Nicht gefunden");
            return false;
        }






@end

the save method is called in another class which owns an instance of NEList

  • 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-10T13:25:13+00:00Added an answer on June 10, 2026 at 1:25 pm

    Ok, all I changed was the “initWithContent” Method and the save method. I’ve commented out your code and under it made the changes to use NSUserDefaults. NSUserDefaults should save a binary file of your Array and later get it back and convert it back to a NSArray. If this doesn’t work just let me know what error your getting.

    -(id) initWithContent {
        self = [super init];
    
        if(self != nil) {
            NSLog(@"load");
            /*
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *documentsDirectory = [paths objectAtIndex:0];
            NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"theFiles"];
    
            theInternArray = [NSMutableArray arrayWithContentsOfFile:filePath];
    
            if(theInternArray == nil) {
                theInternArray = [[NSMutableArray alloc] initWithCapacity:200];
            }
            NSLog(@"second %@", theInternArray);*/
            NSUserDefaults *uDefaults = [NSUserDefaults standardUserDefaults];
            theInternArray = [uDefaults objectForKey:@"internArray"];
            if (!theInternArray)
            {
                theInternArray = [[NSMutableArray alloc] initWithCapacity:200];
            }
            NSLog(@"%@", theInternArray);
    
            return self;
        }
        return nil;
    }
    
    -(BOOL) save {
    
        /*NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"theFiles"];*/
    
        NSUserDefaults *uDefaults = [NSUserDefaults standardUserDefaults];
        [uDefaults setObject:theInternArray forKey:@"internArray"];
    
    
        //return [self.theInternArray writeToFile:filePath atomically:NO];
        return [uDefaults objectForKey:@"internArray"];
    }
    

    Oh, and the reason why your way didn’t work is because it’s not that simple to save a file then get it back. You would need to print out your data from the array (like “item1,item2,item3, etc.” to the file, then parse it and create a NSArray with that data later.

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

Sidebar

Related Questions

I have a class Shape which should have area defined on all instances. area
First of all i have frames on my SD Card and frames are there
I have a class which get all the bytes from a file, then it
I have a method which should consider a collection of instances of a class
I have a class which extends ListActivity within I have all methods for managing
Let me describe my problem first. I have a class which holds a NSMutableDictionary
first of all i have a table like this: userID Day Hour Class ---------------------------------------
First of all I have many Django instances setup and running like this. In
First of all I have searched many times in this forum but none is
First of all I have to say I am new to iOS development. My

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.