Re: (no subject)
Re: (no subject)
- Subject: Re: (no subject)
- From: j o a r <email@hidden>
- Date: Wed, 26 Jul 2006 21:14:22 +0200
On 26 jul 2006, at 20.37, Brad Bumgarner wrote:
Basically, what I am trying to accomplish is a "shift and roll" of
the objects in "anArray." I want to shift every object to the next
higher position and "roll" the last object to the first position in
the array.
How about this alternative implementation:
if ([array count] > 1)
{
[array insertObject: [array lastObject] atIndex: 0];
[array removeLastObject];
}
If you choose to retain your own implementation, keep in mind that
you would at least need to retain your "roller" object while it's not
in the array - The array could be the only one retaining it, and in
that case your implementation would crash!
There also seems to be something wrong with your for-statement
(should be "x==1", and not "x=1"), but I guess that's a simple typo?
Finally, as a matter style, I think that this method should always
return the original array, and never *nil* (unless of course, the
argument to the method is *nil* - in which case you might want to
consider raising an exception).
j o a r
PS: An alternative approach, and perhaps something that could serve
as a tiny exercise for new students of ObjC+Cocoa: This
functionality seems like something that could be added as a category
to NSMutableArray, rather than as a method in some other class.
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
References: | |
| >(no subject) (From: Brad Bumgarner <email@hidden>) |