{"id":15356,"date":"2016-07-27T13:46:04","date_gmt":"2016-07-27T17:46:04","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=15356"},"modified":"2016-07-27T13:47:12","modified_gmt":"2016-07-27T17:47:12","slug":"removing-bit-flags-in-swift-option-sets","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2016\/07\/27\/removing-bit-flags-in-swift-option-sets\/","title":{"rendered":"Removing Bit Flags in Swift Option Sets"},"content":{"rendered":"<p><a href=\"http:\/\/ericasadun.com\/2016\/07\/20\/removing-bit-flags-in-option-sets-or-fun-with-avfoundation\/\">Erica Sadun<\/a>:<\/p>\n<blockquote cite=\"http:\/\/ericasadun.com\/2016\/07\/20\/removing-bit-flags-in-option-sets-or-fun-with-avfoundation\/\">\n<p>This code creates the complete <code>.forbidAll<\/code> set and then removes the local restriction.<\/p>\n<pre>var restrictions: AVAssetReferenceRestrictions = [ .forbidAll ]\nrestrictions .remove(.forbidLocalReferenceToLocal)<\/pre>\n<p>Interestingly,  you can also pass <code>.forbidAll<\/code> without brackets in the current version of Swift and it will compile. [&#8230;] I&rsquo;m told that this option set syntax works because each element of an option set is itself an option set: <code>[.forbidAll]<\/code> is the same type and equal to <code>.forbidAll<\/code>. The array literal form of <code>[.a, .b, .c]<\/code> is syntactic niceness for creating an empty option set and then inserting (i.e. bitwise OR) each element)<\/p><\/blockquote>\n<p>Or you can write:<\/p>\n<blockquote cite=\"http:\/\/ericasadun.com\/2016\/07\/20\/removing-bit-flags-in-option-sets-or-fun-with-avfoundation\/\">\n<pre>let restrictions: AVAssetReferenceRestrictions = .forbidAll.subtracting(.forbidLocalReferenceToLocal)<\/pre>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Erica Sadun: This code creates the complete .forbidAll set and then removes the local restriction. var restrictions: AVAssetReferenceRestrictions = [ .forbidAll ] restrictions .remove(.forbidLocalReferenceToLocal) Interestingly, you can also pass .forbidAll without brackets in the current version of Swift and it will compile. [&#8230;] I&rsquo;m told that this option set syntax works because each element of [&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":[273,69,31,46,30,71,901],"class_list":["post-15356","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-avfoundation","tag-cocoa","tag-ios","tag-languagedesign","tag-mac","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/15356","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=15356"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/15356\/revisions"}],"predecessor-version":[{"id":15364,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/15356\/revisions\/15364"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=15356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=15356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=15356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}