Re: Fast enumeration question.

2015-05-17 Thread dangerwillrobinsondanger
09, Alex Zavatone wrote: > > I'm sure this will sound like the noobiest question ever, but with Fast > Enumeration, if in an if statement within the loop, is there a way to stop > loop execution and essentially do a "proceed to the next item in the list > please"? >

Re: Fast enumeration question.

2015-05-14 Thread Charles Srstka
On May 14, 2015, at 11:52 AM, William Squires wrote: > > Oh well, "continue" it is. Though you can still do it manually, if you want! > :) While that’s true, fast enumeration performs better. Charles ___ Cocoa-dev mail

Re: Fast enumeration question.

2015-05-14 Thread William Squires
then you can test the > loop iterator with a switch() and take appropriate action (or none at all, if > desired.) > > On May 14, 2015, at 11:09 AM, Alex Zavatone wrote: > >> I'm sure this will sound like the noobiest question ever, but with Fast >> Enumeration, if

Re: Fast enumeration question.

2015-05-14 Thread Alex Zavatone
h() and take appropriate action (or none at all, if > desired.) > > On May 14, 2015, at 11:09 AM, Alex Zavatone wrote: > >> I'm sure this will sound like the noobiest question ever, but with Fast >> Enumeration, if in an if statement within the loop, is there a

Re: Fast enumeration question.

2015-05-14 Thread Roland King
'continue’ Just like other c loop constructs. > On 15 May 2015, at 12:09 am, Alex Zavatone wrote: > > I'm sure this will sound like the noobiest question ever, but with Fast > Enumeration, if in an if statement within the loop, is there a way to stop > loop execu

Re: Fast enumeration question.

2015-05-14 Thread William Squires
wrote: > I'm sure this will sound like the noobiest question ever, but with Fast > Enumeration, if in an if statement within the loop, is there a way to stop > loop execution and essentially do a "proceed to the next item in the list > please"? > > Interested in

Re: Fast enumeration question.

2015-05-14 Thread Mike Abdullah
You want: continue; Same as a regular for loop in C. > On 14 May 2015, at 18:09, Alex Zavatone wrote: > > I'm sure this will sound like the noobiest question ever, but with Fast > Enumeration, if in an if statement within the loop, is there a way to stop > loop executio

Fast enumeration question.

2015-05-14 Thread Alex Zavatone
I'm sure this will sound like the noobiest question ever, but with Fast Enumeration, if in an if statement within the loop, is there a way to stop loop execution and essentially do a "proceed to the next item in the list please"? Interested in something like BASIC's next re

Re: Fast Enumeration and remove elements

2015-01-18 Thread Quincey Morris
On Jan 18, 2015, at 12:45 , Trygve Inda wrote: > > NSMutableDictionary* collection; // keys are myID, values are MyObject > > for (MyObject* object in [[self collection] allValues]) > { >[collection removeObjectForKey:[object myID]]; > } What Ken said, plus … — If the collection of values

Re: Fast Enumeration and remove elements

2015-01-18 Thread Ken Thomases
On Jan 18, 2015, at 2:45 PM, Trygve Inda wrote: > So is this safe... > > NSMutableDictionary* collection; // keys are myID, values are MyObject > > for (MyObject* object in [[self collection] allValues]) > { >[collection removeObjectForKey:[object myID]]; > } > > It would seem that this i

Fast Enumeration and remove elements

2015-01-18 Thread Trygve Inda
Apple says: > It is not safe to remove, replace, or add to a mutable collection’s elements > while enumerating through it. If you need to modify a collection during > enumeration, you can either make a copy of the collection and enumerate using > the copy or collect the information you require dur

Re: fast enumeration

2013-04-27 Thread Boyd Collier
arrayOfLabels) { >> // these are the strings that I'm interested in and will use >> NSLog(@"the label from enumeration is %@", aString); >> } > > You don't need to create a separate array, since NSEnumerator alr

Re: fast enumeration

2013-04-27 Thread Jens Alfke
enumeration is %@", aString); > } You don't need to create a separate array, since NSEnumerator already supports fast-enumeration. NSEnumerator *myEnumerator = [arrayOfLabels objectEnumerator]; (void)[myEnumerator nextObject]; // gets us past the first element

fast enumeration

2013-04-27 Thread Boyd Collier
I have an array of NSStrings that in some circumstances, I'd like to go through using fast enumeration starting with the second element in the array. After a bit of fooling around, I came up with the following, which seems to work: NSEnumerator *myEnumerator = [arrayOfL

Re: Fast Enumeration and temporary objects/autoreleasing

2012-04-17 Thread Sean McBride
On Tue, 17 Apr 2012 10:10:44 +1000, Graham Cox said: >Memory management is really quite straightforward I know what you mean, and agree that at its core ref counting is straightforward. But in practice Cocoa memory management is not so simple. Just look at this beast:

Re: Fast Enumeration and temporary objects/autoreleasing

2012-04-17 Thread Charles Srstka
On Apr 17, 2012, at 12:28 AM, Graham Cox wrote: > Well, I don't find ARC to be necessary. I tend to assume it was added to > counter the argument from developers coming from other languages to iOS that > Objective-C is "old fashioned" and requires too much hand-holding on the MM > front that th

Re: Fast Enumeration and temporary objects/autoreleasing

2012-04-17 Thread Jayson Adams
On Apr 17, 2012, at 1:28 AM, Graham Cox wrote: > …having been using Objective C productively for over 10 years now, that I > still find ARC something I have not needed. So far. I'm kinda hoping that > remains true, because it actually seems pretty complicated in order to cover > all the arcan

Re: Fast Enumeration and temporary objects/autoreleasing

2012-04-17 Thread Patrick Robertson
> While you have had the question answered, the fact you asked it shows a misunderstanding about memory management. Next time in my reply I will be clear to state that a) I have realised my mistake b) I have learnt from it to to save you some time writing your response ;-) I do appreciate your hel

Re: Fast Enumeration and temporary objects/autoreleasing

2012-04-17 Thread Graham Cox
On 17/04/2012, at 4:08 PM, Dave Zarzycki wrote: > ARC simply automates and enforces Cocoa conventions. No more, no less. > Therefore those "arcane use-cases" are in fact where programmers get > themselves into really subtle trouble with manual reference counting. Notwithstanding that programm

Re: Fast Enumeration and temporary objects/autoreleasing

2012-04-16 Thread Dave Zarzycki
On Apr 17, 2012, at 1:28 AM, Graham Cox wrote: > …having been using Objective C productively for over 10 years now, that I > still find ARC something I have not needed. So far. I'm kinda hoping that > remains true, because it actually seems pretty complicated in order to cover > all the arcane

Re: Fast Enumeration and temporary objects/autoreleasing

2012-04-16 Thread Graham Cox
On 17/04/2012, at 12:47 PM, Dave Zarzycki wrote: > On Apr 16, 2012, at 8:10 PM, Graham Cox wrote: > >> Memory management is really quite straightforward, and consists of a few >> rules that everything follows (the framework invariably does; your code >> should do). > > > If that were true,

Re: Fast Enumeration and temporary objects/autoreleasing

2012-04-16 Thread Dave Zarzycki
On Apr 16, 2012, at 8:10 PM, Graham Cox wrote: > Memory management is really quite straightforward, and consists of a few > rules that everything follows (the framework invariably does; your code > should do). If that were true, then ARC would not have been necessary. > On 16/04/2012, at 7:4

Re: Fast Enumeration and temporary objects/autoreleasing

2012-04-16 Thread Graham Cox
While you have had the question answered, the fact you asked it shows a misunderstanding about memory management. How fast enumeration is implemented should not make any difference to you, as its user. If it did create temporary objects then it would be responsible for clearing them up. (But

Re: Fast Enumeration and temporary objects/autoreleasing

2012-04-16 Thread Patrick Robertson
> [ array objectAtIndex:i ] doesn't create temporaries either. OK, then that blew my logic right out of the water! Thanks for clearing things up Roland :) On 16 April 2012 10:53, Roland King wrote: > There are no temporary objects created during fast enumeration, you just > get

Re: Fast Enumeration and temporary objects/autoreleasing

2012-04-16 Thread Roland King
There are no temporary objects created during fast enumeration, you just get a reference to one of the objects in the thing you are enumerating. [ array objectAtIndex:i ] doesn't create temporaries either. On Apr 16, 2012, at 5:42 PM, Patrick Robertson wrote: > Hi all, > >

Fast Enumeration and temporary objects/autoreleasing

2012-04-16 Thread Patrick Robertson
Hi all, I've searched the web, but can't seem to find any concrete information on how fast enumeration loops manage temporarily created objects. Would anybody be able to shine some light on whether fast enumeration itself takes care of the objects it creates? So, for example in

Re: What could cause a fast enumeration mutation error in updating tracking areas?

2011-07-29 Thread Gideon King
Thanks for the suggestion Raleigh, but no, there are no other threads involved in any of the tracking area code, and looking at the crash report in more detail, it shows that the array that is being mutated has 27 items in it - the views I create only have one or two tracking areas that I add. I

Re: What could cause a fast enumeration mutation error in updating tracking areas?

2011-07-29 Thread Raleigh Ledet
Do you have another thread that is doing something with tracking areas? -raleigh On Jul 28, 2011, at 11:33 PM, Gideon King wrote: > Hi, I have a problem where a few users of my program are getting the > following exception: > > 0 CoreFoundation 0x7fff862df7b4 __exceptionPreprocess + 180 >

What could cause a fast enumeration mutation error in updating tracking areas?

2011-07-28 Thread Gideon King
Hi, I have a problem where a few users of my program are getting the following exception: 0 CoreFoundation 0x7fff862df7b4 __exceptionPreprocess + 180 1 libobjc.A.dylib 0x7fff84b0ff03 objc_exception_throw + 45 2 CoreFoundation 0x7fff863375bf __NSFastEnumerationMutationHandler + 303 3 A

NSView trackingAreas and fast enumeration mutation

2011-07-22 Thread Gideon King
Hi All, I'm not sure how to track down this issue. A few users of my application have reported the following crash. 0 CoreFoundation 0x7fff8045e7b4 __exceptionPreprocess + 180 1 libobjc.A.dylib 0x7fff8354cf03 objc_exception_throw + 45 2 CoreFoundation 0x7fff804b65bf __NSFastEnumeratio

Re: [Q] Will the be any problem in implementing an NSArray method using fast enumeration?

2011-07-01 Thread Mike Abdullah
pattern is actually written in index based iteration wrapped >> with enumerator pattern. >> Similarly, I guessed fast enumeration was based on either index iteration or >> enumerator pattern. > > No, not necessarily, if by "index iteration" you mean 'ob

Re: [Q] Will the be any problem in implementing an NSArray method using fast enumeration?

2011-07-01 Thread Mike Abdullah
On 1 Jul 2011, at 12:59, Gregory Weston wrote: > Dave DeLong wrote: > >> You can just do: >> >> NSArray *objectsArray = [theArray valueForKey:key]; >> >> And it'll do pretty much the same thing (except that it'll call >> -valueForKey: on each item in the array, and not objectForKey:. However

Re: [Q] Will the be any problem in implementing an NSArray method using fast enumeration?

2011-07-01 Thread Gregory Weston
Dave DeLong wrote: > You can just do: > > NSArray *objectsArray = [theArray valueForKey:key]; > > And it'll do pretty much the same thing (except that it'll call -valueForKey: > on each item in the array, and not objectForKey:. However, if the objects > are NSDictionaries, that's pretty much

Re: [Q] Will the be any problem in implementing an NSArray method using fast enumeration?

2011-06-30 Thread JongAm Park
o unify the way to access >> collection classes no matter what they actually look like. >> So, enumerator pattern is actually written in index based iteration wrapped >> with enumerator pattern. >> Similarly, I guessed fast enumeration was based on either index iteration or >&

Re: [Q] Will the be any problem in implementing an NSArray method using fast enumeration?

2011-06-30 Thread Quincey Morris
ith enumerator pattern. > Similarly, I guessed fast enumeration was based on either index iteration or > enumerator pattern. No, not necessarily, if by "index iteration" you mean 'objectAtIndex:'. NSArray has 2 primitive methods (count and objectAtIndex:) that a concre

Re: [Q] Will the be any problem in implementing an NSArray method using fast enumeration?

2011-06-30 Thread JongAm Park
Um... Thanks for your reply. The last time I used that was about 5 or 6 years ago, and I wondered yesterday where it went away. :) Thanks for pointing out that method. BTW, my actual question was if it is meant to use fast enumeration in a collection class implementation. Although I tried to

Re: [Q] Will the be any problem in implementing an NSArray method using fast enumeration?

2011-06-30 Thread Heath Borders
You might also try HBCollections, a series of collections categories I wrote that makes it easy to do stuff like this. https://github.com/hborders/HBCollections -Heath On Jun 30, 2011 2:10 PM, "Dave DeLong" wrote: ___ Cocoa-dev mailing list (Cocoa-dev

Re: [Q] Will the be any problem in implementing an NSArray method using fast enumeration?

2011-06-30 Thread Dave DeLong
0]; > > for( id item in self ) > { > [objectsArray addObject:[item objectForKey:key]]; > } > > return [[objectsArray copy] autorelease]; > } > > What I'm curious is if it is OK to use fast enumeration to implement

[Q] Will the be any problem in implementing an NSArray method using fast enumeration?

2011-06-30 Thread JongAm Park
]]; } return [[objectsArray copy] autorelease]; } What I'm curious is if it is OK to use fast enumeration to implement an NSArray method itself. Because the mechanism for fast enumeration is already there, I basically think it will be OK. However, wouldn't it better to rely on the most f

Re: Fast enumeration

2010-07-22 Thread Quincey Morris
On Jul 22, 2010, at 16:37, Graham Cox wrote: > On 23/07/2010, at 9:28 AM, Jonathon Kuo wrote: > >> If I use this to go backward through the array: >> >> for (_id in [array reverseObjectEnumerator]) { >> } >> >> ...is it still considered 'fast&#

Re: Fast enumeration

2010-07-22 Thread Graham Cox
On 23/07/2010, at 9:28 AM, Jonathon Kuo wrote: > If I use this to go backward through the array: > > for (_id in [array reverseObjectEnumerator]) { > } > > ...is it still considered 'fast' enumeration? Yes, NSEnumerator conforms to the fast enu

Re: Fast enumeration

2010-07-22 Thread Jonathon Kuo
On Jul 22, 2010, at 1:10 PM, Quincey Morris wrote: > id _id; > > for (_id in array) { > } > > if (_id) > { > } If I use this to go backward through the array: for (_id in [array reverseObjectEnumerator]) { } ...is it still considered &

Re: Fast enumeration

2010-07-22 Thread Quincey Morris
On Jul 22, 2010, at 12:16, Charlie Dickman wrote: > When trying to use, instead, > > for (id _id in _array) { > } > > how, without reverting to effectively using an enumerator as in > > id theID = nil; > for (id _id in _array) { > . > . > . > if (condition) { > theID = _id; > break; > } > .

Fast enumeration

2010-07-22 Thread Charlie Dickman
In the past I have used the construct NSEnumerator *_enumerator = [_array objectEnumerator]; id _id = nil; while (nil != (_id = [_enumerator nextObject])) { . . . if (condition) break; } if (nil == _id) { . . . } to determine if the entire contents of _array had been investigated and, if not

Re: removing all sublayers from a layer with fast enumeration

2009-12-01 Thread Kyle Sluder
On Mon, Nov 30, 2009 at 11:40 AM, Matt Neuburg wrote: > NSArray* arr = [NSArray arrayWithArray: myview.layer.sublayers]; I wouldn't be surprised if -[CALayer sublayers] returns some funky KVO proxy array object that -arrayWithArray: returns unmodified. --Kyle Sluder _

Re: removing all sublayers from a layer with fast enumeration

2009-11-30 Thread Matt Neuburg
On Mon, 30 Nov 2009 14:45:04 -0500, Dave Keck said: >Is the crash due to an exception? Is anything printed to stdout? No, that's part of what's so weird. If we were going to throw an exception, I'd expect to see a coherent explanation in the log. However, the call chain does show we're in somethi

Re: removing all sublayers from a layer with fast enumeration

2009-11-30 Thread Dave Keck
Is the crash due to an exception? Is anything printed to stdout? I'll go out on a limb and say your view is layer-backed instead of layer-hosted... ? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator

Re: removing all sublayers from a layer with fast enumeration

2009-11-30 Thread Matt Neuburg
rrayWithArray: myview.layer.sublayers]; for (CALayer* sub in arr) [sub removeFromSuperlayer]; and I still got the same crash. Enumerating thru arr with objectAtIndex: causes no problem; it's the fast enumeration that's troublesome. m. > On Nov 30, 2009, at 2:23 PM, Matt Neuburg wrote: >

Re: removing all sublayers from a layer with fast enumeration

2009-11-30 Thread Nick Zitzmann
sub in myview.layer.sublayers) > [sub removeFromSuperlayer]; > > This crashes as if the fast enumeration itself were somehow illegal. Why? What happens if you try enumerating on a copy of the sublayer array? That's what I usually do in this situation.

Re: removing all sublayers from a layer with fast enumeration

2009-11-30 Thread David Duncan
ssary. But I'm just curious as to why it doesn't work: for (CALayer* sub in myview.layer.sublayers) [sub removeFromSuperlayer]; This crashes as if the fast enumeration itself were somehow illegal. Why? Thx - m. -- matt neuburg, phd = m...@tidbits.com, <http://www.tidbits.com/matt

removing all sublayers from a layer with fast enumeration

2009-11-30 Thread Matt Neuburg
To remove all sublayers from a layer, it is sufficient to set that layer's sublayers property to nil, so this code is completely unnecessary. But I'm just curious as to why it doesn't work: for (CALayer* sub in myview.layer.sublayers) [sub removeFromSuperlayer]; This crashes

Re: NSPointerArray + fast enumeration for non-object types?

2008-11-20 Thread Ken Ferry
Hi Jim, On Thu, Nov 20, 2008 at 4:02 PM, Jim Correia <[EMAIL PROTECTED]> wrote: > The header documentation for NSPointerArray says: > >> Fast enumeration, copying, and archiving protocols are applicable only >> when NSPointerArray is configured for Object uses. Since

NSPointerArray + fast enumeration for non-object types?

2008-11-20 Thread Jim Correia
The header documentation for NSPointerArray says: Fast enumeration, copying, and archiving protocols are applicable only when NSPointerArray is configured for Object uses. Since the array may contain NULLs, fast enumeration (for..in) will yield NULLs. As a convenience, fast enumeration

Re: Implementing fast enumeration

2008-05-03 Thread Ben
On 3 May 2008, at 02:43, Adam R. Maxwell wrote: On May 2, 2008, at 12:18 PM, Ben wrote: Re-sending as this did not seem to get make it to the list. I have been reading the documentation for implementing the NSFastEnumeration protocol and am having some difficulties following it. [...]

Re: Implementing fast enumeration

2008-05-03 Thread Thomas Backman
Hmm, your previous message/thread made it and has two answers. Regards, Thomas On May 2, 2008, at 10:41 AM, Ben wrote: I have been reading the documentation for implementing the NSFastEnumeration protocol and am having some difficulties following it. For completeness, here is the protocol

Implementing fast enumeration

2008-05-03 Thread Ben
I have been reading the documentation for implementing the NSFastEnumeration protocol and am having some difficulties following it. For completeness, here is the protocol method: - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger

Re: Implementing fast enumeration

2008-05-02 Thread Adam R. Maxwell
On May 2, 2008, at 12:18 PM, Ben wrote: Re-sending as this did not seem to get make it to the list. I have been reading the documentation for implementing the NSFastEnumeration protocol and am having some difficulties following it. [...] Apologies if these are basic questions, but I got

Re: Implementing fast enumeration

2008-05-02 Thread Jens Alfke
On 2 May '08, at 12:18 PM, Ben wrote: I have a C array where the elements within it can be converted into multiple objects. Say I have 5 objects. Do I provide them all in one go and return the total number? Or just one per call and return the number remaining? Return as many as you can a

Implementing fast enumeration

2008-05-02 Thread Ben
Re-sending as this did not seem to get make it to the list. I have been reading the documentation for implementing the NSFastEnumeration protocol and am having some difficulties following it. For completeness, here is the protocol method: - (NSUInteger)countByEnumeratingWithState:(NSFastEnume