{"id":11250,"date":"2015-05-17T14:56:34","date_gmt":"2015-05-17T18:56:34","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=11250"},"modified":"2015-05-17T14:56:34","modified_gmt":"2015-05-17T18:56:34","slug":"how-not-to-crash-2-mutation-exceptions","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2015\/05\/17\/how-not-to-crash-2-mutation-exceptions\/","title":{"rendered":"How Not to Crash #2: Mutation Exceptions"},"content":{"rendered":"<p><a href=\"http:\/\/inessential.com\/2015\/05\/16\/how_not_to_crash_2_mutation_exceptions\">Brent Simmons<\/a>:<\/p>\n<blockquote cite=\"http:\/\/inessential.com\/2015\/05\/16\/how_not_to_crash_2_mutation_exceptions\">\n<p>You get a collection from somewhere and enumerate it &mdash; and then you get an error about the collection being mutated as it was being enumerated. The app crashes.<\/p>\n<p>[&#8230;]<\/p>\n<p>You might push back, citing performance or memory use issues or both &mdash; but I&rsquo;ll admit something: I&rsquo;m a performance junkie, and I spend an inappropriate amount of time in Instruments making sure things are fast and use a non-weird amount of memory. And I&rsquo;ve never, ever found this to be a problem. If your app has performance or memory use issues, the problem is something else, not these copies.<\/p>\n<p>[&#8230;]<\/p>\n<p>There&rsquo;s a general point: if you&rsquo;re getting a collection from code that isn&rsquo;t yours, it doesn&rsquo;t hurt to be defensive and enumerate a copy.<\/p>\n<\/blockquote>\n<p>Swift does something similar automatically, although it probably doesn&rsquo;t work when enumerating an <code>NSArray<\/code> that you receive.<\/p>","protected":false},"excerpt":{"rendered":"<p>Brent Simmons: You get a collection from somewhere and enumerate it &mdash; and then you get an error about the collection being mutated as it was being enumerated. The app crashes. [&#8230;] You might push back, citing performance or memory use issues or both &mdash; but I&rsquo;ll admit something: I&rsquo;m a performance junkie, and I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[131,69,800,31,30,859,54,138,71,901],"class_list":["post-11250","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-bug","tag-cocoa","tag-concurrency","tag-ios","tag-mac","tag-nsarray","tag-objective-c","tag-optimization","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/11250","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=11250"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/11250\/revisions"}],"predecessor-version":[{"id":11251,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/11250\/revisions\/11251"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=11250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=11250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=11250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}