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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:01:31+00:00 2026-05-27T13:01:31+00:00

I have a singleton data manager object that manages the connection to a web

  • 0

I have a singleton data manager object that manages the connection to a web service, processes the data and then updates a mutable dictionary with the objects. All requests for this dictionary are via this singleton instance that I have created. Now and again I will get conflicts as I am obviously editing a mutable object from many threads and so get the occasional EXC_BAD_ACCESS.

I could implement @synchronized methods or use NSLock but as I am already making extensive use of Grand Central Dispatch I was wondering if there is anything I can do there by forcing them all down one thread synchronously? I also am not sure if the above methods would work and how they would be implemented.

Example code below. The exception can occur in the getObjectArray method as I could be adding to it/updating sub object/deleting in the translateToObjectFromDict method.

NSMutableDictionary *staticDictionary;

-(NSArray *)getObjectArray{

    NSArray *returnArray = [[[NSArray alloc]init]autorelease];
    returnArray = [self.staticDictionary allValues];
    return returnArray;
}

-(void)translateToObjectFromDict:(NSDictionary *)sourceDictionary{



    dispatch_group_t taskGroup = dispatch_group_create();
    dispatch_queue_t queue = dispatch_get_global_queue(0,0);


    dispatch_group_async(taskGroup,queue,^(){

    for (id key in sourceDictionary) {
        NSDictionary *subDictionary = [sourceDictionary objectForKey:key];
        for (id key in subDictionary) {

            NSArray *theObjData = [subDictionary objectForKey:key];
            if ([theObjData count] == 12) {

               theObj *temptheObj = [[PINKtheObj alloc] initWith......
                    NSString *unihex = temptheObj.unihex;

                    if ([self.staticDictionary objectForKey:unihex]){
                        PINKtheObj *localtheObj = [self.staticDictionary objectForKey:unihex];
                        if (temptheObj.time > localtheObj.time) {
                            [localtheObj updatetheObjWith.......
                        [temptheObj release];
                    }else{
                        [self.staticDictionary setObject:temptheObj forKey:unihex];
                    }
            }

        }
    }
    });

    dispatch_group_notify(taskGroup, queue, ^{
        NSDictionary *getMainDict = [self.mainDictionary objectForKey:@"theObjs"];

        for (id key in self.staticDictionary) {
            if (![getMainDict objectForKey:key]){
                [self.removeArray addObject:[self.staticDictionary objectForKey:key]];
            }
        }

        [[NSNotificationCenter defaultCenter]postNotificationName:@"updated" object:nil];
    });
    dispatch_release(taskGroup);

}
  • 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-27T13:01:31+00:00Added an answer on May 27, 2026 at 1:01 pm

    I think you should supply all your calls (objectForKey:, setObject:ForKey:, etc.) to your staticDictionary in your own serial queue. Create it when singleton initializes and use everywhere.
    In your header file create ivar.

    dispatch_queue_t queueDict;
    

    In .m file just add to init

    queueDict = dispatch_queue_create("com.yourid.yoursingleton.queueDict ", NULL);
    

    When you want to access or put data into dictionary just make

    dispatch_async(queueDict, ^(){
    [staticDict setObject:obj forKey:key]; //example
    }
    

    You can use dispatch_sync if you want your task to wait for returned value.

    __block id returnValue;
    dispatch_sync(queueDict, ^(){
    returnValue = [statictDict objectForKey:key]; //example
    }
    obj = returnValue;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The setup: I have a singleton data access manager object, call it Manager. I
I have an activity that starts a service. There is also a singleton Data
I have a singleton object called PoolManager that loads and saves some data in
I have a singleton object that use another object (not singleton), to require some
I have a few camel routes that call an external web service, i need
The goal is to have a singleton data controller class called FetchData.h/.m that pulls
I have a singleton called Singleton that manages certain variables needed across the application
I have a singleton class to download some data from the web. I am
I have a singleton class which manages data and database handling of my application.
I have a singleton object in iOS that when instantiated parses a CSV file

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.