• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSDictionary @synchronize to read multiple objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSDictionary @synchronize to read multiple objects


  • Subject: NSDictionary @synchronize to read multiple objects
  • From: Trygve Inda <email@hidden>
  • Date: Mon, 31 Mar 2014 22:16:07 -0700
  • Thread-topic: NSDictionary @synchronize to read multiple objects

I have an object with a dictionary property defined as:

@property (nonatomic, retain) NSMutableDictionary*  myDict;

This gets set when it is received via an AppleEvent from another
application.



Multiple threads in the receiving app need to read (the threads never write,
only read) from the Dictionary like:

[self setValueOne:[[myDict objectForKey:kValueOneKey] intValue]];
[self setValueTwo:[[myDict objectForKey:kValueTwoKey] intValue]];

I need to be able to set a new myDict and not have it happen between the
reading of different values from the dictionary by other threads.

Should this be done best with a @synchronize around a copy:

@synchronize(myDict)
{
    myCopy = [[NSDictionary alloc] initWithDictionary:myDict copyItems:YES];
}

[self setValueOne:[[myCopy objectForKey:kValueOneKey] intValue]];
[self setValueTwo:[[myCopy objectForKey:kValueTwoKey] intValue]];
[myCopy release];

This would seem to ensure that valueOne and valueTwo were obtained from the
same instance of a given dictionary and that the dictionary did not change
in between the reading and setting of these two dictionary content objects.

I need to avoid valueOne and valueTwo coming from two different instances of
myDict.

Thanks,

Trygve



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: NSDictionary @synchronize to read multiple objects
      • From: Ken Thomases <email@hidden>
    • Re: NSDictionary @synchronize to read multiple objects
      • From: Jens Alfke <email@hidden>
  • Prev by Date: Re: NSBox Border Width Property
  • Next by Date: Re: NSDictionary @synchronize to read multiple objects
  • Previous by thread: Re: NSBox Border Width Property
  • Next by thread: Re: NSDictionary @synchronize to read multiple objects
  • Index(es):
    • Date
    • Thread