{"id":12100,"date":"2015-08-27T14:41:29","date_gmt":"2015-08-27T18:41:29","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=12100"},"modified":"2015-08-27T17:55:25","modified_gmt":"2015-08-27T21:55:25","slug":"swift-2-beta-6","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2015\/08\/27\/swift-2-beta-6\/","title":{"rendered":"Swift 2 Beta 6"},"content":{"rendered":"<p><a href=\"http:\/\/www.russbishop.net\/swift-2-beta-6\">Russ Bishop<\/a>:<\/p>\n<blockquote cite=\"http:\/\/www.russbishop.net\/swift-2-beta-6\">\n<p>A new <code>try?<\/code> keyword has been added. This attempts an operation that may throw (fail). If it succeeds the result is wrapped in an optional. If it fails the error is ignored and <code>nil<\/code> is returned. This seems like a pragmatic compromise but I have to imagine someone lost a battle somewhere because a lot of programmers are going to slap a <code>try?<\/code> on it and ignore all errors.<\/p>\n<\/blockquote>\n<p>This is a good addition that was <a href=\"http:\/\/mjtsai.com\/blog\/2015\/07\/23\/failable-init-vs-throws\/\">suggested<\/a> last month. I&rsquo;m not worried about errors being ignored because the compiler warns if the result of <code>try?<\/code> is unused. It lets you <a href=\"http:\/\/appventure.me\/2015\/08\/25\/optional-throw-swift\/\">ignore<\/a> the specific error that you got, but you still have to handle the fact that there was an error.<\/p>\n<blockquote cite=\"http:\/\/www.russbishop.net\/swift-2-beta-6\">\n<p>Variadic parameters can appear anywhere in the parameter list; presumably the compiler disambiguates them by type and\/or by consuming values off the right-hand side of argument list until the non-variadic arguments are satisfied.<\/p>\n<\/blockquote>\n<p>It looks to me like it&rsquo;s simpler than that, and you simply use a named parameter to signal the end of the variadic parameter. Perhaps in the future it will be possible to support multiple variadic parameters in this way. For now, the main benefit is that you can more easily use trailing closures.<\/p>\n<blockquote cite=\"http:\/\/www.russbishop.net\/swift-2-beta-6\">\n<p><code>extend<\/code> was renamed <code>appendContentsOf<\/code> and <code>splice<\/code> was renamed <code>insertContentsOf<\/code><\/p>\n<\/blockquote>\n<p>It&rsquo;s good to see Apple keeping some of Foundation&rsquo;s good ideas.<\/p>\n<blockquote cite=\"http:\/\/www.russbishop.net\/swift-2-beta-6\">\n<p>Most APIs that take closures or <code>@autoclosure<\/code> parameters use <code>rethrows<\/code> properly so you can pass throwing methods to <code>map<\/code>, <code>filter<\/code>, etc. It also allows short-circuiting operators like <code>&amp;&amp;<\/code>, <code>||<\/code>, or <code>??<\/code> to work with expressions that throw.<\/p>\n<\/blockquote>\n<p>This should make error handling easier than <a href=\"http:\/\/mjtsai.com\/blog\/2015\/06\/19\/swift-2-error-handling-continued\/\">before<\/a>.<\/p>\n<p>There are still some bugs, though:<\/p>\n<blockquote cite=\"http:\/\/www.russbishop.net\/swift-2-beta-6\">\n<p>Declaring multiple globals in a single <code>var<\/code> or <code>let<\/code> may cause corruption of their values; the workaround is to declare them with separate <code>var<\/code> or <code>let<\/code> statements.<\/p>\n<\/blockquote>\n<p><a href=\"http:\/\/ericasadun.com\/2015\/08\/24\/yoda-alert-try-swiftlang-hint-beta-6\/\">Erica Sadun<\/a>:<\/p>\n<blockquote cite=\"http:\/\/ericasadun.com\/2015\/08\/24\/yoda-alert-try-swiftlang-hint-beta-6\/\"><p>You can combine <code>try?<\/code> with <code>??<\/code> for fallback values but you must surround the try in parens[&#8230;]<\/p><\/blockquote>\n<p><a href=\"http:\/\/ericasadun.com\/2015\/08\/26\/beta-6-lazy-swiftlang\/\">Erica Sadun<\/a>:<\/p>\n<blockquote cite=\"http:\/\/ericasadun.com\/2015\/08\/26\/beta-6-lazy-swiftlang\/\"><p>Beta 6 introduces a <code>lazy<\/code> property on sequences.<\/p><p>[&#8230;]<\/p><p>This property is implemented in <code>CollectionType<\/code>, <code>LazyCollectionType<\/code>, and <code>LazySequenceType<\/code> extensions. You use it to delay evaluation on things like map and filter that are normally eager.<\/p><\/blockquote>\n<p><a href=\"http:\/\/ericasadun.com\/2015\/08\/26\/how-to-join-and-extend-in-beta-6-swiftlang\/\">Erica Sadun<\/a>:<\/p>\n<blockquote cite=\"http:\/\/ericasadun.com\/2015\/08\/26\/how-to-join-and-extend-in-beta-6-swiftlang\/\"><p><code>Join<\/code> has become <code>joinWithSeparator<\/code>, which you call after a sequence, interposing a separator between the elements of a sequence.<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Russ Bishop: A new try? keyword has been added. This attempts an operation that may throw (fail). If it succeeds the result is wrapped in an optional. If it fails the error is ignored and nil is returned. This seems like a pragmatic compromise but I have to imagine someone lost a battle somewhere because [&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,857,71,901],"class_list":["post-12100","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-languagedesign","tag-nserror","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/12100","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=12100"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/12100\/revisions"}],"predecessor-version":[{"id":12111,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/12100\/revisions\/12111"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=12100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=12100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=12100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}