Changing head item on a (GCD) Queue


Dave
 

Hi All,

I need to do some changes to a Mac Objective-C project to do the following:

1. Data is Sent to a Delegate method in a class.

2. The data is validated by this method and if ok, it needs to be processed in background, e.g. added to a Queue.

3. There is a possibility that the data coming in makes items already queued for processing invalid, this happens when a burst of data is sent in a small time-frame. In this case, I want to examine the head of the queue (e.g. the next data block to be processed) and if this new data makes it invalid, overwrite it.

As an example I have this on the queue:

Head: Data.type = NewLocation, Data.Location = 123,

The new Data is

Data.type = NewLocation, Data.Location = 124,

Instead of adding this to the queue, I want to overwrite the exist Head item with the new DataLocation (124).

I’m trying to figure out the best (modern) way to this which I assume is to use GCD? Any suggestions, pointers or sample code on how to do this would be greatly appreciated.

All the Best
Dave

Join cocoa@apple-dev.groups.io to automatically receive all group messages.