{"id":47551,"date":"2025-04-29T13:58:27","date_gmt":"2025-04-29T17:58:27","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=47551"},"modified":"2025-04-29T13:58:27","modified_gmt":"2025-04-29T17:58:27","slug":"swiftui-macos-toolbar-examples","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2025\/04\/29\/swiftui-macos-toolbar-examples\/","title":{"rendered":"SwiftUI macOS Toolbar Examples"},"content":{"rendered":"<p><a href=\"https:\/\/ohanaware.com\/swift\/macOSToolbarExamples.html\">Sam Rowlands<\/a> (<a href=\"https:\/\/x.com\/Sam_Ohanaware\/status\/1916695621500801132\">tweet<\/a>):<\/p>\n<blockquote cite=\"https:\/\/ohanaware.com\/swift\/macOSToolbarExamples.html\"><p>There&rsquo;s several ways to create a toolbar and a bunch of options for it also.<\/p><p>[&#8230;]<\/p><p>Adding a search field to the toolbar is easier than you think, simply add the <code>.searchable(text:)<\/code> modifier to a view within your content view.<\/p><\/blockquote>\n<p>There are <a href=\"https:\/\/developer.apple.com\/documentation\/swiftui\/view\/searchable(text:placement:prompt:)\">options<\/a> for the placement and prompt, but nothing on the documentation page tells how to use the search menu. I guess this is done using the separate <a href=\"https:\/\/developer.apple.com\/documentation\/swiftui\/view\/searchscopes(_:scopes:)\">searchScopes(_:scopes:)<\/a> function, which seems limited compared to what <a href=\"https:\/\/developer.apple.com\/documentation\/appkit\/nssearchfield\">NSSearchField<\/a> offers. On the other hand, the SwiftUI version has support for <a href=\"https:\/\/developer.apple.com\/documentation\/swiftui\/suggesting-search-terms\">suggestions<\/a>, which I don&rsquo;t think Apple ever added to AppKit except for its own apps.<\/p>\n\n<blockquote cite=\"https:\/\/ohanaware.com\/swift\/macOSToolbarExamples.html\">\n<p>Putting a segmented picker too close to the search field can result in it becoming trapped and unaccessible from the chevron menu when the search field is highlighted and then loses focus. I have filed this as a bug with Apple FB17392294.<\/p><\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2025\/01\/13\/mac-toolbar-guidelines\/\">Mac Toolbar Guidelines<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Sam Rowlands (tweet): There&rsquo;s several ways to create a toolbar and a bunch of options for it also.[&#8230;]Adding a search field to the toolbar is easier than you think, simply add the .searchable(text:) modifier to a view within your content view. There are options for the placement and prompt, but nothing on the documentation page [&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":"2025-04-29T17:58:30Z","apple_news_api_id":"3791ffa5-58da-4247-a455-9b1f18e2bdb0","apple_news_api_modified_at":"2025-04-29T17:58:30Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AN5H_pVjaQkekVZsfGOK9sA","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,71,343,901,1812],"class_list":["post-47551","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-mac","tag-macos-15-sequoia","tag-programming","tag-search","tag-swift-programming-language","tag-swiftui"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/47551","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=47551"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/47551\/revisions"}],"predecessor-version":[{"id":47552,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/47551\/revisions\/47552"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=47551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=47551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=47551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}