{"id":12021,"date":"2015-08-19T10:17:12","date_gmt":"2015-08-19T14:17:12","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=12021"},"modified":"2015-08-19T10:17:12","modified_gmt":"2015-08-19T14:17:12","slug":"testing-swifts-errortype","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2015\/08\/19\/testing-swifts-errortype\/","title":{"rendered":"Testing Swift&rsquo;s ErrorType"},"content":{"rendered":"<p><a href=\"https:\/\/realm.io\/news\/testing-swift-error-type\/\">Marius Rackwitz<\/a>:<\/p>\n<blockquote cite=\"https:\/\/realm.io\/news\/testing-swift-error-type\/\">\n<p>Further investigation via LLDB reveals that the protocol has some hidden requirements.<\/p>\n<pre>(lldb) type lookup ErrorType\nprotocol ErrorType {\n  var _domain: Swift.String { get }\n  var _code: Swift.Int { get }\n}<\/pre>\n<p>It becomes clear how <code class=\"highlighter-rouge\">NSError<\/code> fulfills this definition: it has these properties, backed by ivars, which Swift can access without dynamic dispatch. What is still unclear is how Swift&rsquo;s first class enums can automatically fulfill this protocol. Perhaps there is still some magic involved?<\/p>\n<p>[&#8230;]<\/p>\n<p>Sure, you could catch it as any generic error and then manually check the fields <code>_domain<\/code> and <code>_code<\/code>, but there are more elegant alternatives.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Marius Rackwitz: Further investigation via LLDB reveals that the protocol has some hidden requirements. (lldb) type lookup ErrorType protocol ErrorType { var _domain: Swift.String { get } var _code: Swift.Int { get } } It becomes clear how NSError fulfills this definition: it has these properties, backed by ivars, which Swift can access without dynamic [&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":[31,46,30,857,71,901,268],"class_list":["post-12021","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-ios","tag-languagedesign","tag-mac","tag-nserror","tag-programming","tag-swift-programming-language","tag-testing"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/12021","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=12021"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/12021\/revisions"}],"predecessor-version":[{"id":12022,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/12021\/revisions\/12022"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=12021"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=12021"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=12021"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}