{"id":17042,"date":"2017-01-29T16:30:19","date_gmt":"2017-01-29T21:30:19","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=17042"},"modified":"2017-01-29T16:30:19","modified_gmt":"2017-01-29T21:30:19","slug":"swift-weak-references-and-type-erasure","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2017\/01\/29\/swift-weak-references-and-type-erasure\/","title":{"rendered":"Swift Weak References and Type Erasure"},"content":{"rendered":"<p><a href=\"http:\/\/curtclifton.net\/weak-references-and-type-erasure\">Curt Clifton<\/a>:<\/p>\n<blockquote cite=\"http:\/\/curtclifton.net\/weak-references-and-type-erasure\"><p>In one of my side projects, two interesting Swift problems&mdash;heterogeneous arrays and weak references&mdash;collided in an interesting way.<\/p><p>[&#8230;]<\/p><p>How can we clean up the old <code><span>caller<\/span><\/code>s? We need some logic that tells us when a signal has been deallocated. But we don&rsquo;t have a direct reference to any signals at all from the data model. We gave that up when we used type erasure. The only references to the signals are inside the <code><span>caller<\/span><\/code>s.<\/p><p>That realization leads to the insight that unlocks this problem. We can capture a weak reference to the signal inside another closure that tells us whether or not a signal has been deallocated[&#8230;]<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Curt Clifton: In one of my side projects, two interesting Swift problems&mdash;heterogeneous arrays and weak references&mdash;collided in an interesting way.[&#8230;]How can we clean up the old callers? We need some logic that tells us when a signal has been deallocated. But we don&rsquo;t have a direct reference to any signals at all from the data [&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":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","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,571,71,901],"class_list":["post-17042","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-languagedesign","tag-memory-management","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/17042","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=17042"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/17042\/revisions"}],"predecessor-version":[{"id":17043,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/17042\/revisions\/17043"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=17042"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=17042"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=17042"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}