{"id":11093,"date":"2015-04-28T12:43:01","date_gmt":"2015-04-28T16:43:01","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=11093"},"modified":"2015-04-28T12:43:35","modified_gmt":"2015-04-28T16:43:35","slug":"unmanaged","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2015\/04\/28\/unmanaged\/","title":{"rendered":"Unmanaged"},"content":{"rendered":"<p><a href=\"http:\/\/nshipster.com\/unmanaged\/\">Nate Cook<\/a>:<\/p>\n<blockquote cite=\"http:\/\/nshipster.com\/unmanaged\/\">\n<p>An <code>Unmanaged&lt;T&gt;<\/code> instance wraps a CoreFoundation type <code>T<\/code>, preserving a reference to the underlying object as long as the <code>Unmanaged<\/code> instance itself is in scope. There are two ways to get a Swift-managed value out of an <code>Unmanaged<\/code> instance:<\/p>\n<blockquote>\n<ul>\n<li><p><code>takeRetainedValue()<\/code>: returns a Swift-managed reference to the wrapped instance, decrementing the reference count while doing so&mdash;use with the return value of a Create Rule function.<\/p><\/li>\n<li><p><code>takeUnretainedValue()<\/code>: returns a Swift-managed reference to the wrapped instance <em>without<\/em> decrementing the reference count&mdash;use with the return value of a Get Rule function.<\/p><\/li>\n<\/ul>\n<\/blockquote>\n<p>In practice, you&rsquo;re better off not even working with <code>Unmanaged<\/code> instances directly. Instead, <code>take...<\/code> the underlying instance immediately from the function&rsquo;s return value and bind <em>that<\/em>.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Nate Cook: An Unmanaged&lt;T&gt; instance wraps a CoreFoundation type T, preserving a reference to the underlying object as long as the Unmanaged instance itself is in scope. There are two ways to get a Swift-managed value out of an Unmanaged instance: takeRetainedValue(): returns a Swift-managed reference to the wrapped instance, decrementing the reference count while [&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":[55,69,861,571,71,901],"class_list":["post-11093","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-arc","tag-cocoa","tag-core-foundation","tag-memory-management","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/11093","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=11093"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/11093\/revisions"}],"predecessor-version":[{"id":11094,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/11093\/revisions\/11094"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=11093"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=11093"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=11093"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}