views:

11

answers:

1

Hello all,

I would like to know how to remove duplicate nsoperations, i.e is there a way to check the nsoperation queue and see if I am making a duplicate request?

Basically, I am requesting images depending on the iphone screen rotation. When the view is loaded the shouldautorate is called twice.

If(rotation==portrait){
  request portrait image.
}

The issue is that shoud autorotate will be checked twice. And on both ocassions, it will turn out to be portrait hence requesting the same image twice. Anyone with a good idea? I forgot to mention I am using a queue.

Thanks.

+1  A: 

NEW, better answer:

Don't use the shouldAutorotate... method. It only asks whether a rotation is allowed to happen. This may happen any time and may not necessarily lead to a rotation. Instead, use willRotate... or didRotate..., as these methods are only invoked exactly once and only if the rotation actually happens.

Your operation will then be added only once.


OLD, but not false answer:

How about using a instance variable to remember the last seen rotation? Like so:

if (rotation != lastSeenRotation) {
    // REQUEST image here
}
Max Seelemann
Yer I thought about that but is that not hacky ?
Oh well nvm, will stick to that. It is way simpler than checking my queue and seeing if I have duplicates. Prevention is better.
I was told we should not be using the shouldautorotate method and use the willrotate or didrotate method.
definitely, use the latter. The reason is simple: the first one will ASK for a rotation, but does not actually require the rotation to happen. The latter two actually PERFORM the rotation. And (clumsy me) in those cases you also don't need the check: the rotation action happens only once. I'll adjust my post accordingly.
Max Seelemann