{"id":29735,"date":"2020-08-10T16:06:28","date_gmt":"2020-08-10T20:06:28","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=29735"},"modified":"2020-08-10T16:06:28","modified_gmt":"2020-08-10T20:06:28","slug":"swiftui-alerts","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2020\/08\/10\/swiftui-alerts\/","title":{"rendered":"SwiftUI Alerts"},"content":{"rendered":"<p><a href=\"http:\/\/www.thomashanning.com\/swiftui-alert\/\">Thomas Hanning<\/a>:<\/p>\n<blockquote cite=\"http:\/\/www.thomashanning.com\/swiftui-alert\/\">\n<p>SwiftUI refreshes the view whenever the bool value changes since it is a state. As a consequence, the alert gets displayed if it&rsquo;s set to true.<\/p>\n<p>[&#8230;]<\/p>\n<p>It&rsquo;s not possible to add more than two buttons though.<\/p>\n<p>[&#8230;]<\/p>\n<p>But for a view it&rsquo;s not so uncommon to have more than one scenario for displaying an alert. [&#8230;] Unfortunately, this doesn&rsquo;t work. The reason is that every view can only have one alert.<\/p>\n<\/blockquote>\n<p>This is not a good advertisement for the Swift UI way of doing things.<\/p>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2020\/08\/06\/emulating-equal-size-constraints-in-swiftui\/\">Emulating Equal-Size Constraints in SwiftUI<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2020\/01\/31\/swiftui-for-mac\/\">SwiftUI for Mac<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Thomas Hanning: SwiftUI refreshes the view whenever the bool value changes since it is a state. As a consequence, the alert gets displayed if it&rsquo;s set to true. [&#8230;] It&rsquo;s not possible to add more than two buttons though. [&#8230;] But for a view it&rsquo;s not so uncommon to have more than one scenario for [&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":"2020-08-10T20:06:30Z","apple_news_api_id":"a8d74488-122d-4558-9366-3b5e9c009857","apple_news_api_modified_at":"2020-08-10T20:06:30Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AqNdEiBItRViTZjtenACYVw","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":[31,1837,30,1891,71,901,1812],"class_list":["post-29735","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-ios","tag-ios-14","tag-mac","tag-macos-11-0","tag-programming","tag-swift-programming-language","tag-swiftui"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/29735","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=29735"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/29735\/revisions"}],"predecessor-version":[{"id":29736,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/29735\/revisions\/29736"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=29735"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=29735"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=29735"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}