{"id":13982,"date":"2016-03-25T10:05:55","date_gmt":"2016-03-25T14:05:55","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=13982"},"modified":"2016-03-25T10:06:52","modified_gmt":"2016-03-25T14:06:52","slug":"surprises-with-swift-extensions","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2016\/03\/25\/surprises-with-swift-extensions\/","title":{"rendered":"Surprises With Swift Extensions"},"content":{"rendered":"<p><a href=\"https:\/\/pspdfkit.com\/blog\/2016\/surprises-with-swift-extensions\/\">Peter Steinberger<\/a>:<\/p>\n<blockquote cite=\"https:\/\/pspdfkit.com\/blog\/2016\/surprises-with-swift-extensions\/\">\n<p>These seemingly innocent extensions were overriding private API. Apple&rsquo;s private API detection is not super sophisticated and wasn&rsquo;t triggered when the app was uploaded to the App Store. It&rsquo;s also not a public symbol so there were no warnings, not even a log message. Unprefixed categories are always dangerous, especially on classes that you do not own, like <code>UIViewController<\/code>. In PSPDFKit, we use categories for shared code, but prefix any method with <code>pspdf_<\/code> to be absolutely sure we do not hit any name clashes. It&rsquo;s certainly not pretty, and prefixes in Swift look even more alien, yet as you can see in this bug hunt, they are definitely necessary.<\/p>\n<p>[&#8230;]<\/p>\n<p>You can use <code>@objc(prefix_name)<\/code> to keep the name pretty in Swift and expose a prefixed version for the ObjC runtime.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Peter Steinberger: These seemingly innocent extensions were overriding private API. Apple&rsquo;s private API detection is not super sophisticated and wasn&rsquo;t triggered when the app was uploaded to the App Store. It&rsquo;s also not a public symbol so there were no warnings, not even a log message. Unprefixed categories are always dangerous, especially on classes that [&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":[131,69,31,30,54,1013,71,901],"class_list":["post-13982","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-bug","tag-cocoa","tag-ios","tag-mac","tag-objective-c","tag-private-api","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13982","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=13982"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13982\/revisions"}],"predecessor-version":[{"id":13984,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13982\/revisions\/13984"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=13982"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=13982"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=13982"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}