{"id":37753,"date":"2022-11-29T16:12:04","date_gmt":"2022-11-29T21:12:04","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=37753"},"modified":"2022-11-29T16:12:04","modified_gmt":"2022-11-29T21:12:04","slug":"swift-mutating-functions-and-property-observers","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2022\/11\/29\/swift-mutating-functions-and-property-observers\/","title":{"rendered":"Swift Mutating Functions and Property Observers"},"content":{"rendered":"<p><a href=\"https:\/\/christiantietze.de\/posts\/2022\/11\/mutating-struct-and-state-observers\/\">Christian Tietze<\/a>:<\/p>\n<blockquote cite=\"https:\/\/christiantietze.de\/posts\/2022\/11\/mutating-struct-and-state-observers\/\">\n<p>I was under the (wrong) assumption that the <code>mutating func<\/code> needed to, well, somehow <em>mutate<\/em> the receiver of that method call, like change a property value. And that this in turn would be noted &ldquo;somewhere&rdquo;. Conversely, I was under the (wrong) assumption that a <code>mutating func<\/code> without any mutations inside would behave 100% like a regular, non-mutating function.<\/p>\n<p>[&#8230;]<\/p>\n<p>A pretty nice consequence is that you can use <code>mutating func<\/code> to change a reference type property inside a value type, and have references to the value type still know that it has changed:<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Christian Tietze: I was under the (wrong) assumption that the mutating func needed to, well, somehow mutate the receiver of that method call, like change a property value. And that this in turn would be noted &ldquo;somewhere&rdquo;. Conversely, I was under the (wrong) assumption that a mutating func without any mutations inside would behave 100% [&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":"2022-11-29T21:12:06Z","apple_news_api_id":"11c06d78-ef9c-48ab-ae9c-3aaa20a6c294","apple_news_api_modified_at":"2022-11-29T21:12:06Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AEcBteO-cSKuunDqqIKbClA","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":[46,71,901],"class_list":["post-37753","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-languagedesign","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/37753","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=37753"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/37753\/revisions"}],"predecessor-version":[{"id":37754,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/37753\/revisions\/37754"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=37753"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=37753"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=37753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}