Re: Modifying outside properties from NSOperation subclass
Re: Modifying outside properties from NSOperation subclass
- Subject: Re: Modifying outside properties from NSOperation subclass
- From: Ken Thomases <email@hidden>
- Date: Mon, 14 Dec 2009 20:23:33 -0600
On Dec 14, 2009, at 6:54 PM, PCWiz wrote:
> On 2009-12-14, at 5:51 PM, Nick Zitzmann wrote:
>
>> On Dec 14, 2009, at 5:19 PM, PCWiz wrote:
>>
>>> I need to modify an NSMutableDictionary in my delegate class from within an NSOperation subclass. What's the best way to do this? I could just use the property setter method, but is this even acceptable?
>>
>> More details, please. Is your operation enqueued or invoked directly? And are you seeking to replace the entire dictionary or just its contents?
>
> Its being loaded into an NSOperationQueue, and I'm using methods like setObject:forKey: on the dictionary, not replacing the whole thing.
I recommend against doing it this way. Have your operation object message the object which owns the dictionary, not the dictionary itself.
Ideally, an operation would receive all of the data it needs to do its work before it is started. That data would be isolated to the operation; it would _not_ be a reference to data shared by other objects. Then, the operation would do all of its work. When the operation completes its work, it may have a result. It should pass that result to another object just before it finishes (or it may simply store its result in one of its own properties to be queried by its owner). It is often convenient for the result to be something as simple as an array or dictionary, but it may be some other custom class of object. It is also sometimes convenient for the operation to send its result message on the main thread using -performSelectorOnMainThread:... if the result will be used to update the GUI.
Regards,
Ken
_______________________________________________
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