{"id":23242,"date":"2018-10-29T16:30:42","date_gmt":"2018-10-29T20:30:42","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=23242"},"modified":"2018-10-31T15:17:32","modified_gmt":"2018-10-31T19:17:32","slug":"nsmutabledictionarys-practical-limit","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2018\/10\/29\/nsmutabledictionarys-practical-limit\/","title":{"rendered":"NSMutableDictionary&rsquo;s Practical Limit"},"content":{"rendered":"<p><a href=\"https:\/\/twitter.com\/bSr43\/status\/1056842375736295424\">Vincent B&eacute;nony<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/bSr43\/status\/1056842375736295424\"><p>Pro tip: if your Objective-C application deals with a huge collection of objects, avoid relying on NSMutableDictionary as the &ldquo;count&rdquo; method returns the number of objects&#8230; modulo 0x2000000  &ldquo;allKeys&rdquo; and &ldquo;allValues&rdquo; are also affected&#8230;<\/p><\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/gregtitus\/status\/1056968885809831936\">Greg Titus<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/gregtitus\/status\/1056968885809831936\">\n<p>Fun fact! If you make your dictionary with 0x2000001 objects in Swift and then cast it to an NSDictionary, then it works just fine from Objective-C. Can&rsquo;t be a mutable dictionary that way, though.<\/p>\n<\/blockquote>\n\n<p id=\"nsmutabledictionarys-practical-limit-update-2018-10-31\">Update (2018-10-31): <a href=\"https:\/\/twitter.com\/bSr43\/status\/1057584054118309893\">Vincent B&eacute;nony<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/bSr43\/status\/1057584054118309893\">\n<p>It depends on the private class used by Foundation. For instance, if I build the dictionary with &laquo;&nbsp;dictionaryWithObjects:forKeys:&nbsp;&raquo; it works perfectly, but as soon as I create a mutable copy, it fails.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Vincent B&eacute;nony: Pro tip: if your Objective-C application deals with a huge collection of objects, avoid relying on NSMutableDictionary as the &ldquo;count&rdquo; method returns the number of objects&#8230; modulo 0x2000000 &ldquo;allKeys&rdquo; and &ldquo;allValues&rdquo; are also affected&#8230; Greg Titus: Fun fact! If you make your dictionary with 0x2000001 objects in Swift and then cast it 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":"2018-10-29T20:30:43Z","apple_news_api_id":"6ff94e5e-7c46-4605-af96-0314c19863f7","apple_news_api_modified_at":"2018-10-31T19:17:35Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAQ==","apple_news_api_share_url":"https:\/\/apple.news\/Ab_lOXnxGRgWvlgMUwZhj9w","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,31,1610,30,1609,54,71,901],"class_list":["post-23242","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-bug","tag-cocoa","tag-ios","tag-ios-12","tag-mac","tag-macos-10-14","tag-objective-c","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/23242","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=23242"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/23242\/revisions"}],"predecessor-version":[{"id":23257,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/23242\/revisions\/23257"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=23242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=23242"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=23242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}