• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: removing all sublayers from a layer with fast enumeration
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: removing all sublayers from a layer with fast enumeration


  • Subject: Re: removing all sublayers from a layer with fast enumeration
  • From: Matt Neuburg <email@hidden>
  • Date: Mon, 30 Nov 2009 11:40:02 -0800
  • Thread-topic: removing all sublayers from a layer with fast enumeration

On or about 11/30/09 11:33 AM, thus spake "David Duncan"
<email@hidden>:

> Your modifying an array that is being enumerated, which is illegal.

I thought of that, of course, but I doubted that could be the reason,
because I changed the code to look like this:

NSArray* arr = [NSArray arrayWithArray: 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 <email@hidden> wrote:
>
>> 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 as if the fast enumeration itself were somehow illegal.
>> Why?
>> Thx -

--
matt neuburg, phd = email@hidden, http://www.tidbits.com/matt/
pantes anthropoi tou eidenai oregontai phusei
Among the 2007 MacTech Top 25, http://tinyurl.com/2rh4pf
AppleScript: the Definitive Guide, 2nd edition
http://www.tidbits.com/matt/default.html#applescriptthings
Take Control of Exploring & Customizing Snow Leopard
http://tinyurl.com/kufyy8
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
TidBITS, Mac news and reviews since 1990, http://www.tidbits.com



_______________________________________________

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

  • Follow-Ups:
    • Re: removing all sublayers from a layer with fast enumeration
      • From: Dave Keck <email@hidden>
References: 
 >Re: removing all sublayers from a layer with fast enumeration (From: David Duncan <email@hidden>)

  • Prev by Date: Re: removing all sublayers from a layer with fast enumeration
  • Next by Date: Re: removing all sublayers from a layer with fast enumeration
  • Previous by thread: Re: removing all sublayers from a layer with fast enumeration
  • Next by thread: Re: removing all sublayers from a layer with fast enumeration
  • Index(es):
    • Date
    • Thread