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

  • Home
  • SEARCH
  • 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 7839979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:37:11+00:00 2026-06-02T15:37:11+00:00

i am creating an application that needs to work with categories. there will be

  • 0

i am creating an application that needs to work with categories.
there will be a basic categories set that i want to deliver with the app, but it can be edited by the user (remove, add categories). the basic .plist will not be changed but read just once, and then stored mutable somewhere else.

here is my approach:

Default Categories delivered in categoryCollection.plist with the app.
defaultCategories.plist will be the new .plist file that gets manipulated

Default Dictionary stylecategoryCollection.plist

to read the categories into a NSMutableSet i use:

    NSString *mainBundlePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *dictPath = [mainBundlePath stringByAppendingPathComponent:@"defaultCategories"];
    NSDictionary * dict = [[NSDictionary alloc]initWithContentsOfFile:dictPath];

    // testing if the file has values, if not load from categoryCollection.plist
    if (dict.count == 0) {
        NSString *tempPath = [[NSBundle mainBundle] pathForResource:@"categoryCollection" ofType:@"plist"];
        dict = [NSMutableDictionary dictionaryWithContentsOfFile:tempPath];
        [dict writeToFile:dictPath atomically:YES];
    }

    // load into NSMutableSet
    [self.stringsCollection addObjectsFromArray:[[dict objectForKey:@"categories"]objectForKey:@"default"]];

to add a category i call this function:

-(void)addCategoryWithName:(NSString *)name{

    NSString *mainBundlePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *dictPath = [mainBundlePath stringByAppendingPathComponent:@"defaultCategories"];
    NSMutableDictionary * dict = [[NSMutableDictionary alloc]initWithContentsOfFile:dictPath];
    [[[dict objectForKey:@"categories"]objectForKey:@"default"]addObject:name];

    [dict writeToFile:dictPath atomically:YES];

    self.needsToUpdateCategoryCollection = YES;
}

and to delete a string i use:

-(void)removeCategoryWithName:(NSString *)name{

    NSString *mainBundlePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *dictPath = [mainBundlePath stringByAppendingPathComponent:@"defaultCategories"];
    NSDictionary * dict = [[NSDictionary alloc]initWithContentsOfFile:dictPath];

    NSMutableArray *temp = [NSMutableArray arrayWithArray:[[dict objectForKey:@"categories"]objectForKey:@"default"]] ;

    for (NSString *string in temp) {
        if ([string isEqualToString:name]) {
            [temp removeObject:string];
            break;
        }
    }
    [[dict objectForKey:@"categories"]removeObjectForKey:@"default"];
    [[dict objectForKey:@"categories"] setValue:temp forKey:@"default"];


    [dict writeToFile:dictPath atomically:YES];
    self.needsToUpdateCategoryCollection = YES;
}

the code actually works quite well, but i wonder if this massive overhead of multiple I/O operations, tests etc is really necessary or if there is a more elegant solution to store a collection of strings and let them be manipulated?

or if you see any speedbump that might improve the speed (because i get some small lags with that code when having a lot of categories)

any thoughts?
sebastian

  • 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-02T15:37:12+00:00Added an answer on June 2, 2026 at 3:37 pm

    Your approach works fine, but it does more work than it is necessary by writing the results every time the collection is modified. It is writing of the file that is the costliest part of your add and remove methods.

    One way to address the problem would be to read your categories when your app starts up, cache your NSMutableDictionary in a singleton object, and reference it as your app runs. When end users make changes, you update the dictionary only in memory; do not write the data to the file immediately.

    In your app delegate, listen to the applicationDidEnterBackground: event, and write the data to the file in that handler. Also listen to the applicationDidEnterForeground: event, and read your file into NSMutableDictionary. This will save you a lot of CPU cycles, and provide smoother end-user experience.

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

Sidebar

Related Questions

I am creating an application that will have a list of items that can
Let's say your creating an application that needs to send you an email monthly.
I am creating a rails application that needs to store a large amount of
I'm creating an application that will store geolocation data for specific transactions. Should I
I am creating an application that is similar to the camera app provided in
I am creating a web application that will display the dates of various events
I am creating a forecasting application that will run simulations for various modes that
I have an old c++ application that needs to be modified to work with
I am trying to write an installer (by creating a .vdproj) that will work
I am working on an simple c++ application for my work that needs to

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.