{"id":29012,"date":"2020-05-22T15:57:39","date_gmt":"2020-05-22T19:57:39","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=29012"},"modified":"2020-05-22T15:57:39","modified_gmt":"2020-05-22T19:57:39","slug":"marking-unused-required-swift-initializers-as-unavailable","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2020\/05\/22\/marking-unused-required-swift-initializers-as-unavailable\/","title":{"rendered":"Marking Unused Required Swift Initializers As Unavailable"},"content":{"rendered":"<p><a href=\"https:\/\/www.jessesquires.com\/blog\/2020\/05\/20\/marking-unused-required-initializers-as-unavailable\/\">Jesse Squires<\/a>:<\/p>\n<blockquote cite=\"https:\/\/www.jessesquires.com\/blog\/2020\/05\/20\/marking-unused-required-initializers-as-unavailable\/\"><p>However, if you do not use Interface Builder, then <code>init(coder:)<\/code> is irrelevant and will never be called. It is annoying boilerplate. But the real problem is that Xcode (and presumably other editors) will offer <code>init(coder:)<\/code> as an auto-complete option when initializing your view or view controller. That is not ideal, because it is not a valid way to initialize your custom view or view controller. Luckily, you can use Swift&rsquo;s <a href=\"https:\/\/docs.swift.org\/swift-book\/ReferenceManual\/Attributes.html\"><code>@available<\/code> attribute<\/a> to prevent this, which also has the benefit of more clearly communicating that you should not use this initializer.<\/p><\/blockquote>\n<p>It&rsquo;s annoying how each of my view and managed object subclasses has to reimplement a <code>required<\/code> initializer that I never intend to call.<\/p>","protected":false},"excerpt":{"rendered":"<p>Jesse Squires: However, if you do not use Interface Builder, then init(coder:) is irrelevant and will never be called. It is annoying boilerplate. But the real problem is that Xcode (and presumably other editors) will offer init(coder:) as an auto-complete option when initializing your view or view controller. That is not ideal, because it is [&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":"2020-05-22T19:57:42Z","apple_news_api_id":"cb6a810b-cd6d-4ccd-940a-5cff88e1ad5e","apple_news_api_modified_at":"2020-05-22T19:57:42Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/Ay2qBC81tTM2UClz_iOGtXg","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":[69,109,31,1667,30,1666,71,901],"class_list":["post-29012","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cocoa","tag-coredata","tag-ios","tag-ios-13","tag-mac","tag-macos-10-15","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/29012","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=29012"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/29012\/revisions"}],"predecessor-version":[{"id":29013,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/29012\/revisions\/29013"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=29012"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=29012"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=29012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}