{"id":45697,"date":"2024-11-06T15:44:46","date_gmt":"2024-11-06T20:44:46","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=45697"},"modified":"2024-11-06T15:44:46","modified_gmt":"2024-11-06T20:44:46","slug":"swift-format-in-xcode-16","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2024\/11\/06\/swift-format-in-xcode-16\/","title":{"rendered":"Swift Format in Xcode 16"},"content":{"rendered":"<p><a href=\"https:\/\/troz.net\/post\/2024\/swift_format\/\">Sarah Reichelt<\/a> (<a href=\"https:\/\/mastodon.social\/@troz\/113434655266958603\">Mastodon<\/a>):<\/p>\n<blockquote cite=\"https:\/\/troz.net\/post\/2024\/swift_format\/\"><p>In Xcode 16, Apple quietly introduced the ability to format your Swift files using Swift Format. I&rsquo;m a long-time user of SwiftLint, but having such a tool built into Xcode would be a great convenience, so I decided to give it a try. Here is my description of why I use such a tool, how well it works compared to the alternatives, and how I configured it for my own purposes.<\/p><p>[&#8230;]<\/p><p>The name Apple chose is logical but confusing. I had experimented with Nick Lockwood&rsquo;s <a href=\"https:\/\/github.com\/nicklockwood\/SwiftFormat\">SwiftFormat<\/a>\n a few years ago, but found that I preferred SwiftLint, so I stuck with the latter. When I saw that Xcode included Swift Format, I assumed that they had acquired Nick&rsquo;s formatter but it appears to be a different tool, officially called <a href=\"https:\/\/github.com\/swiftlang\/swift-format\">swift-format<\/a>. It&rsquo;s downloaded as part of the toolchain when you install Xcode 16, so no further installation is required.<\/p><p>[&#8230;]<\/p><p>After reverting to the original code again, I chose <strong>Editor -&gt; Structure -&gt; Format File with &lsquo;swift-format&rsquo;<\/strong>[&#8230;]<\/p><p>This fixed the indentation and the whitespace issues. Interestingly, it split the long function call and definition over multiple lines, but still with more than one argument per line.<\/p><\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2024\/10\/31\/xcode-16-1\/\">Xcode 16.1<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2024\/10\/07\/xcode-16-folders-and-groups\/\">Xcode 16 Folders and Groups<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2024\/09\/12\/xcode-16\/\">Xcode 16<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2020\/02\/28\/swift-argument-parser\/\">Swift Argument Parser<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Sarah Reichelt (Mastodon): In Xcode 16, Apple quietly introduced the ability to format your Swift files using Swift Format. I&rsquo;m a long-time user of SwiftLint, but having such a tool built into Xcode would be a great convenience, so I decided to give it a try. Here is my description of why I use such [&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-11-06T20:44:49Z","apple_news_api_id":"a3c06276-297e-4a65-a3fa-8ce9c3d68f14","apple_news_api_modified_at":"2024-11-06T20:44:49Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/Ao8Bidil-SmWj-ozpw9aPFA","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":[30,2598,74,71,226],"class_list":["post-45697","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-mac","tag-macos-15-sequoia","tag-opensource","tag-programming","tag-xcode"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/45697","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=45697"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/45697\/revisions"}],"predecessor-version":[{"id":45698,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/45697\/revisions\/45698"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=45697"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=45697"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=45697"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}