{"id":2602,"date":"2018-01-24T14:09:04","date_gmt":"2018-01-24T10:09:04","guid":{"rendered":"https:\/\/blog.alwawee.ru\/?p=2602"},"modified":"2018-01-24T14:10:34","modified_gmt":"2018-01-24T10:10:34","slug":"why-swift-at-least-should-be-faster-than-objective-c","status":"publish","type":"post","link":"https:\/\/blog.alwawee.ru\/?p=2602","title":{"rendered":"Why Swift at least should be faster than Objective C"},"content":{"rendered":"<p>In sections <strong>Optionals and Chaining<\/strong> and <strong>Value types<\/strong> there is an answer to a post topic question &#8211; Why Swift at least should be faster than Objective C <\/p>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Swift_(programming_language)\" rel=\"noopener\" target=\"_blank\">https:\/\/en.wikipedia.org\/wiki\/Swift_(programming_language)<\/a><\/p>\n<p>Using\u00a0guard\u00a0has three benefits. While the syntax can act as an\u00a0if\u00a0statement, its primary benefit is inferring non-nullability. Where an\u00a0if\u00a0statement requires a case,\u00a0guard\u00a0assumes the case based on the condition provided. Also, since\u00a0guard\u00a0contains no scope, with exception of the\u00a0else\u00a0closure,\u00a0leaseStart\u00a0is presented as an unwrapped optional to the guard&#8217;s super-scope. Lastly, if the\u00a0guard\u00a0statement&#8217;s test fails, Swift requires the\u00a0else\u00a0to exit the current method or loop, ensuring\u00a0leaseStart\u00a0never is accessed when\u00a0nil. This is performed with the keywords\u00a0return,\u00a0continue,\u00a0break, or\u00a0throw.<br \/>\nObjC was weakly typed, and allowed any method to be called on any object at any time. If the method call failed, there was a default handler in the runtime that returned nil. That meant that no unwrapping or testing was needed, the equivalent statement in ObjC:<\/p>\n<p>leaseStart = [[[aBuilding tenantList:5] leaseDetails] startDate]<\/p>\n<p>would return nil and this could be tested. However, this also demanded that all method calls be dynamic, which introduces significant overhead. Swift&#8217;s use of optionals provides a similar mechanism for testing and dealing with nils, but does so in a way that allows the compiler to use static dispatch because the unwrapping action is called on a defined instance (the wrapper), versus occurring in the runtime dispatch system.<\/p>\n<p>The programmer is free to choose which semantics are more appropriate for each data structure in the application. Larger structures like windows would be defined as classes, allowing them to be passed around as pointers. Smaller structures, like a 2D point, can be defined as structs, which will be pass-by-value and allow direct access to their internal data with no dereference. The performance improvement inherent to the pass-by-value concept is such that Swift uses these types for almost all common data types, including\u00a0Int\u00a0and\u00a0Double, and types normally represented by objects, like\u00a0String\u00a0and\u00a0Array.[41]\u00a0Using value types can result in significant performance improvements in user applications also.[42]<\/p>\n<p>To ensure that even the largest structs do not cause a performance penalty when they are handed off, Swift uses\u00a0copy on write\u00a0so that the objects are copied only if and when the program attempts to change a value in them. This means that the various accessors have what is in effect a pointer to the same data storage, but this takes place far below the level of the language, in the computer&#8217;s\u00a0memory management unit\u00a0(MMU). So while the data is physically stored as one instance in memory, at the level of the application, these values are separate, and physical separation is enforced by copy on write only if needed.[43]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In sections Optionals and Chaining and Value types there is an answer to a post topic question &#8211; Why Swift at least should be faster than Objective C https:\/\/en.wikipedia.org\/wiki\/Swift_(programming_language) Using\u00a0guard\u00a0has three benefits. While the syntax can act as an\u00a0if\u00a0statement, its primary benefit is inferring non-nullability. Where an\u00a0if\u00a0statement requires a case,\u00a0guard\u00a0assumes the case based on the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-2602","post","type-post","status-publish","format-standard","hentry","category-ios"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Why Swift at least should be faster than Objective C - Denis Kutlubaev<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.alwawee.ru\/?p=2602\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Why Swift at least should be faster than Objective C - Denis Kutlubaev\" \/>\n<meta property=\"og:description\" content=\"In sections Optionals and Chaining and Value types there is an answer to a post topic question &#8211; Why Swift at least should be faster than Objective C https:\/\/en.wikipedia.org\/wiki\/Swift_(programming_language) Using\u00a0guard\u00a0has three benefits. While the syntax can act as an\u00a0if\u00a0statement, its primary benefit is inferring non-nullability. Where an\u00a0if\u00a0statement requires a case,\u00a0guard\u00a0assumes the case based on the [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog.alwawee.ru\/?p=2602\" \/>\n<meta property=\"og:site_name\" content=\"Denis Kutlubaev\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/alwaweemobile\" \/>\n<meta property=\"article:published_time\" content=\"2018-01-24T10:09:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-01-24T10:10:34+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/blog.alwawee.com\/?attachment_id=1982\" \/>\n<meta name=\"author\" content=\"Denis Kutlubaev\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Denis Kutlubaev\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2602#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2602\"},\"author\":{\"name\":\"Denis Kutlubaev\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\"},\"headline\":\"Why Swift at least should be faster than Objective C\",\"datePublished\":\"2018-01-24T10:09:04+00:00\",\"dateModified\":\"2018-01-24T10:10:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2602\"},\"wordCount\":487,\"commentCount\":0,\"articleSection\":[\"iOS\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2602#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2602\",\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2602\",\"name\":\"Why Swift at least should be faster than Objective C - Denis Kutlubaev\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#website\"},\"datePublished\":\"2018-01-24T10:09:04+00:00\",\"dateModified\":\"2018-01-24T10:10:34+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2602#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2602\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2602#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/blog.alwawee.ru\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Why Swift at least should be faster than Objective C\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#website\",\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/\",\"name\":\"Denis Kutlubaev\",\"description\":\"iOS Development\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/blog.alwawee.ru\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\",\"name\":\"Denis Kutlubaev\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"caption\":\"Denis Kutlubaev\"},\"description\":\"iOS Developer, creator of Tornado Browser and many other popular apps\",\"sameAs\":[\"http:\\\/\\\/dennis.alwawee.com\"],\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Why Swift at least should be faster than Objective C - Denis Kutlubaev","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.alwawee.ru\/?p=2602","og_locale":"en_US","og_type":"article","og_title":"Why Swift at least should be faster than Objective C - Denis Kutlubaev","og_description":"In sections Optionals and Chaining and Value types there is an answer to a post topic question &#8211; Why Swift at least should be faster than Objective C https:\/\/en.wikipedia.org\/wiki\/Swift_(programming_language) Using\u00a0guard\u00a0has three benefits. While the syntax can act as an\u00a0if\u00a0statement, its primary benefit is inferring non-nullability. Where an\u00a0if\u00a0statement requires a case,\u00a0guard\u00a0assumes the case based on the [&hellip;]","og_url":"https:\/\/blog.alwawee.ru\/?p=2602","og_site_name":"Denis Kutlubaev","article_publisher":"https:\/\/www.facebook.com\/alwaweemobile","article_published_time":"2018-01-24T10:09:04+00:00","article_modified_time":"2018-01-24T10:10:34+00:00","og_image":[{"url":"http:\/\/blog.alwawee.com\/?attachment_id=1982","type":"","width":"","height":""}],"author":"Denis Kutlubaev","twitter_misc":{"Written by":"Denis Kutlubaev","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blog.alwawee.ru\/?p=2602#article","isPartOf":{"@id":"https:\/\/blog.alwawee.ru\/?p=2602"},"author":{"name":"Denis Kutlubaev","@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7"},"headline":"Why Swift at least should be faster than Objective C","datePublished":"2018-01-24T10:09:04+00:00","dateModified":"2018-01-24T10:10:34+00:00","mainEntityOfPage":{"@id":"https:\/\/blog.alwawee.ru\/?p=2602"},"wordCount":487,"commentCount":0,"articleSection":["iOS"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/blog.alwawee.ru\/?p=2602#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blog.alwawee.ru\/?p=2602","url":"https:\/\/blog.alwawee.ru\/?p=2602","name":"Why Swift at least should be faster than Objective C - Denis Kutlubaev","isPartOf":{"@id":"https:\/\/blog.alwawee.ru\/#website"},"datePublished":"2018-01-24T10:09:04+00:00","dateModified":"2018-01-24T10:10:34+00:00","author":{"@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7"},"breadcrumb":{"@id":"https:\/\/blog.alwawee.ru\/?p=2602#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.alwawee.ru\/?p=2602"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blog.alwawee.ru\/?p=2602#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog.alwawee.ru\/"},{"@type":"ListItem","position":2,"name":"Why Swift at least should be faster than Objective C"}]},{"@type":"WebSite","@id":"https:\/\/blog.alwawee.ru\/#website","url":"https:\/\/blog.alwawee.ru\/","name":"Denis Kutlubaev","description":"iOS Development","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.alwawee.ru\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7","name":"Denis Kutlubaev","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","caption":"Denis Kutlubaev"},"description":"iOS Developer, creator of Tornado Browser and many other popular apps","sameAs":["http:\/\/dennis.alwawee.com"],"url":"https:\/\/blog.alwawee.ru\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts\/2602","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2602"}],"version-history":[{"count":3,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts\/2602\/revisions"}],"predecessor-version":[{"id":2605,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts\/2602\/revisions\/2605"}],"wp:attachment":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2602"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}