{"id":2356,"date":"2010-04-09T10:52:21","date_gmt":"2010-04-09T14:52:21","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=2356"},"modified":"2014-07-14T10:18:50","modified_gmt":"2014-07-14T14:18:50","slug":"comparison-of-objective-c-enumeration-techniques","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2010\/04\/09\/comparison-of-objective-c-enumeration-techniques\/","title":{"rendered":"Comparison of Objective-C Enumeration Techniques"},"content":{"rendered":"<p><a href=\"http:\/\/www.mikeash.com\/pyblog\/friday-qa-2010-04-09-comparison-of-objective-c-enumeration-techniques.html\">Mike Ash<\/a>:<\/p>\r\n<blockquote cite=\"http:\/\/www.mikeash.com\/pyblog\/friday-qa-2010-04-09-comparison-of-objective-c-enumeration-techniques.html\"><p>If there are multiple contiguous object stores, <code>NSFastEnumeration<\/code> allows the collection to return interior pointers one after another, allowing for a quick loop implementation over each store, and requiring an Objective-C message only for getting the next interior pointer. For collections without contiguous storage, <code>NSFastEnumeration<\/code> allows the collection to copy objects out to temporary storage in bulk, reaping many of the same benefits. For collections where none of this works, <code>NSFastEnumeration<\/code> still allows a collection to efficiently return objects one by one.&#8230;Nice syntax, good performance, it&rsquo;s a great combination.<\/p><\/blockquote>\r\n<p>Unfortunately, you can&rsquo;t use fast enumeration if you support Mac OS X 10.4. Currently, I write all my loops using a <code>foreach<\/code> macro, which conditionally compiles to <a href=\"http:\/\/mjtsai.com\/blog\/2006\/07\/15\/cocoa-foreach-macro\/\">IMP-caching and <code>NSEnumerator<\/code><\/a> under 32 bit and <code>for&#8230;in<\/code> under 64-bit.<\/p>","protected":false},"excerpt":{"rendered":"<p>Mike Ash: If there are multiple contiguous object stores, NSFastEnumeration allows the collection to return interior pointers one after another, allowing for a quick loop implementation over each store, and requiring an Objective-C message only for getting the next interior pointer. For collections without contiguous storage, NSFastEnumeration allows the collection to copy objects out to [&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,2],"tags":[69,941,54,71],"class_list":["post-2356","post","type-post","status-publish","format-standard","hentry","category-programming-category","category-technology","tag-cocoa","tag-macros","tag-objective-c","tag-programming"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/2356","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=2356"}],"version-history":[{"count":4,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/2356\/revisions"}],"predecessor-version":[{"id":9148,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/2356\/revisions\/9148"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=2356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=2356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=2356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}