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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:20:34+00:00 2026-05-22T15:20:34+00:00

I have a singleton delayed-transaction manager class, which is responsible for enqueueing and dequeueing

  • 0

I have a singleton delayed-transaction manager class, which is responsible for enqueueing and dequeueing iphone-to-app-server transactions that cannot complete due to a variety of factors (network reachability, proximity, etc). When reachability/proximity is restored, it attempts to dequeue the the transactions. It is also possible that another transaction would be enqueued at the same time that dequeueing is happening.
My understanding is that NSUserDefaults is a thread-safe wrapper of a mutable dictionary SO link which is exactly what I want. That same SO link opines that NSUserDefaults is for user preferences.

These transactions are not user preferences but that’s the functionality I want.
So, here’s the question, can I read/write/synchronize an NSMutableDictionary of transactions in NSUserDefaults without corrupting the dictionary, or do I need to implement my own locking mechanism with reading and writing with NSKeyed(Un)Archiver (see below)?

Some code:

 - (void) queThing:(Thing *)aThing {

   // @synchronized this block?
   NSMutableDictionary * QD = [self readFile];
   [QD setObject:aThing forKey:aThing.thingId];
   [self writeFile: QD];
   // @ sync?
}
- (void) writeFile:(NSMutableDictionary *)theData {
    BOOL status = [NSKeyedArchiver archiveRootObject: theData toFile:archivePath];
    if ( !status) {
       DebugLog(@"Write to archive failed.");
    } else {
       DebugLog(@"Write to archive SUCCEEDED.");
    }
 }
 - (NSMutableDictionary *) readFile {
   NSMutableDictionary *Q =[NSKeyedUnarchiver  unarchiveObjectWithFile:archivePath];
   if ( ! Q ) {
       Q = [NSMutableDictionary dictionaryWithCapacity:2];
   }
   return Q;
 }

Dequeue:

    // @synchronized this block?
    NSMutableDictionary * QD = [self readFile];
    [QD removeObjectForKey:thing.thingId];
    [self writeFile: QD];
    // @ sync?
  • 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-22T15:20:35+00:00Added an answer on May 22, 2026 at 3:20 pm

    It’s true that NSUserDefaults is thread safe (it says so in the docs). But conceptually, it’s really not the place to be doing stuff like you’re doing. It will work, but you’ll end up with your transaction IDs potentially polluting a preferences namespace that you may find you want to use later with a preferences bundle, etc.

    Doing locking around the reads/writes should work. Putting locks around file ops feels weird to me; you could also keep the queue object in memory (with locking) and only flush it periodically from e.g. the main thread. Or use a lockfile on disk to protect the writes/reads.

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

Sidebar

Related Questions

I want to have singleton class that its object is not statically created. having
I have a singleton class that inherits from sprite so that it can access
The goal is to have a singleton data controller class called FetchData.h/.m that pulls
I have a guice based app that now needs multiple instances of a given
I have a singleton that uses the static readonly T Instance = new T();
I have a singleton bean which needs for each call of a function to
I have a singleton class for global access to config information. This singleton class
i have singleton class , when calling one of the singleton methods more then
I have a singleton that I use for creating an application wide report. As
so let's say you have a singleton pattern or whatever: class Smth{ public static

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.