{"id":43329,"date":"2024-05-20T14:46:18","date_gmt":"2024-05-20T18:46:18","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=43329"},"modified":"2025-10-29T09:38:35","modified_gmt":"2025-10-29T13:38:35","slug":"swift-formatstyle-issues","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2024\/05\/20\/swift-formatstyle-issues\/","title":{"rendered":"Swift FormatStyle Issues"},"content":{"rendered":"<p><a href=\"https:\/\/wadetregaskis.com\/fucking-formatstyle\/\">Wade Tregaskis<\/a>:<\/p>\n<blockquote cite=\"https:\/\/wadetregaskis.com\/fucking-formatstyle\/\"><p>They&rsquo;re terser than using their otherwise more powerful cousins the <code><a href=\"https:\/\/developer.apple.com\/documentation\/foundation\/formatter\">Formatter<\/a><\/code>s, as they support a &ldquo;fluent&rdquo; style of property-based access, which tends to read more naturally and usually avoids having to define variables to hold the formatter.<\/p><p>[&#8230;]<\/p><p>They almost always break Xcode&rsquo;s auto-complete, which is a problem since their syntax is non-trivial and unintuitive.<\/p><p>They&rsquo;re hard to understand &#x2013; and to even find in Apple&rsquo;s official documentation &#x2013; because there&rsquo;s so many protocols and indirection involved.<\/p><p>It&rsquo;s particularly hard to tell where the inexplicable gaps are. e.g. <code><a href=\"https:\/\/developer.apple.com\/documentation\/swift\/double\">Double<\/a><\/code> doesn&rsquo;t support <code><a href=\"https:\/\/developer.apple.com\/documentation\/foundation\/bytecountformatstyle\">ByteCountFormatStyle<\/a><\/code>, even though logically it should <em>and<\/em> Xcode will sometimes auto-complete as if it does.<\/p><\/blockquote>\n<p>I haven&rsquo;t used the new formatter API much because it isn&rsquo;t available in the SDK that I&rsquo;m targeting. I like that it&rsquo;s terser and doesn&rsquo;t require tracking a formatter instance. But it&rsquo;s probably not terse enough that I would use it directly vs. via a more semantically named helper method. And I agree that it&rsquo;s not actually that easy to use if you don&rsquo;t already know what you&rsquo;re doing.<\/p>\n\n<p><a href=\"https:\/\/wadetregaskis.com\/the-only-usable-bytecountformatstyle-is-decimal\/\">Wade Tregaskis<\/a>:<\/p>\n<blockquote cite=\"https:\/\/wadetregaskis.com\/the-only-usable-bytecountformatstyle-is-decimal\/\">\n<p>Alas, they don&rsquo;t always work correctly; some of these formatters contain egregious bugs.<\/p>\n<p>In particular, <code>ByteCountFormatStyle<\/code> pretends to support multiple numeric bases &#x2013; decimal and binary &#x2013; but it doesn&rsquo;t[&#8230;] Note how it still uses <em>decimal<\/em> units, &ldquo;kB&rdquo;.  Decimal is not binary.  I mean, duh, right?  But apparently Apple don&rsquo;t know this.<\/p>\n<\/blockquote>\n<p><code>NSByteCountFormatter<\/code> behaves the same way. I don&rsquo;t think it&rsquo;s a bug so much as Apple deciding to never display <a href=\"https:\/\/en.wikipedia.org\/wiki\/Binary_prefix\">binary prefixes<\/a> even though it is intentional about calculating memory sizes as binary and file sizes as decimal.<\/p>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/02\/06\/example-custom-formatstyles\/\">Example Custom FormatStyles<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2022\/06\/10\/formatstyles-in-ios-16-and-macos-13\/\">FormatStyles in iOS 16 and macOS 13<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2022\/03\/22\/swift-formatstyle-deep-dive\/\">Swift FormatStyle Deep Dive<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2022\/01\/26\/swift-foundation-formatter-improvements\/\">Swift Foundation Formatter Improvements<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Wade Tregaskis: They&rsquo;re terser than using their otherwise more powerful cousins the Formatters, as they support a &ldquo;fluent&rdquo; style of property-based access, which tends to read more naturally and usually avoids having to define variables to hold the formatter.[&#8230;]They almost always break Xcode&rsquo;s auto-complete, which is a problem since their syntax is non-trivial and unintuitive.They&rsquo;re [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2024-05-20T18:46:22Z","apple_news_api_id":"32af7e23-5529-4824-96a3-08eeb22bbae0","apple_news_api_modified_at":"2024-05-20T18:47:08Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAQ==","apple_news_api_share_url":"https:\/\/apple.news\/AMq9-I1UpSCSWowjusiu64A","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":[69,164,31,2321,30,2385,71,174,2854,901],"class_list":["post-43329","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cocoa","tag-documentation","tag-ios","tag-ios-17","tag-mac","tag-macos-14-sonoma","tag-programming","tag-storage","tag-swift-foundation","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/43329","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=43329"}],"version-history":[{"count":3,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/43329\/revisions"}],"predecessor-version":[{"id":43332,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/43329\/revisions\/43332"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=43329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=43329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=43329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}