{"id":14596,"date":"2016-05-20T10:49:49","date_gmt":"2016-05-20T14:49:49","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=14596"},"modified":"2017-03-15T12:51:40","modified_gmt":"2017-03-15T16:51:40","slug":"swift-assertions","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2016\/05\/20\/swift-assertions\/","title":{"rendered":"Swift Assertions"},"content":{"rendered":"<p><a href=\"http:\/\/andybargh.com\/swift-assertions\/\">Andy Bargh<\/a>:<\/p>\n<blockquote cite=\"http:\/\/andybargh.com\/swift-assertions\/\">\n<p>If we dive into a bit more of the detail behind assertions in Swift, we find that the Swift language actually supports five, different types of assertion.  These are:<br \/> &#8211; <code>assert()<\/code><br \/> &#8211; <code>precondition()<\/code><br \/> &#8211; <code>assertionFailure()<\/code><br \/> &#8211; <code>preconditionFailure()<\/code><br \/> &#8211; <code>fatalError()<\/code><\/p><p>Each of these assertions behave slightly differently and in the majority of cases the optimisation level that the code is compiled with has a direct effect on whether they are evaluated or not.<\/p>\n<\/blockquote>\n<p>Update (2017-03-15): Previously: <a href=\"http:\/\/mjtsai.com\/blog\/2015\/12\/16\/precondition-vs-assert-in-swift\/\">precondition vs. assert in Swift<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Andy Bargh: If we dive into a bit more of the detail behind assertions in Swift, we find that the Swift language actually supports five, different types of assertion. These are: &#8211; assert() &#8211; precondition() &#8211; assertionFailure() &#8211; preconditionFailure() &#8211; fatalError()Each of these assertions behave slightly differently and in the majority of cases the optimisation [&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":[46,71,901],"class_list":["post-14596","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-languagedesign","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14596","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=14596"}],"version-history":[{"count":3,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14596\/revisions"}],"predecessor-version":[{"id":17419,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14596\/revisions\/17419"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=14596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=14596"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=14596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}