{"id":21029,"date":"2018-04-01T21:12:54","date_gmt":"2018-04-02T01:12:54","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=21029"},"modified":"2018-04-12T13:41:06","modified_gmt":"2018-04-12T17:41:06","slug":"swift-4-1","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2018\/04\/01\/swift-4-1\/","title":{"rendered":"Swift 4.1"},"content":{"rendered":"<p><a href=\"https:\/\/swift.org\/blog\/swift-4-1-released\/\">Ted Kremenek<\/a>:<\/p>\n<blockquote cite=\"https:\/\/swift.org\/blog\/swift-4-1-released\/\"><p>Swift 4.1 adds more generics features to the language, furthering the goals set out in the <a href=\"https:\/\/github.com\/apple\/swift\/blob\/master\/docs\/GenericsManifesto.md\">Swift Generics Manifesto<\/a>. The following generics-related proposals have been implemented in this release:<\/p><ul><li><a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/master\/proposals\/0143-conditional-conformances.md\">SE-0143 Conditional Conformance<\/a><\/li><li><a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/master\/proposals\/0157-recursive-protocol-constraints.md\">SE-0157 Support recursive constraints on associated types<\/a><\/li><li><a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/master\/proposals\/0185-synthesize-equatable-hashable.md\">SE-0185 Synthesizing Equatable and Hashable conformance<\/a><\/li><li><a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/master\/proposals\/0187-introduce-filtermap.md\">SE-0187 Introduce Sequence.compactMap(_:)<\/a><\/li><li><a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/master\/proposals\/0188-stdlib-index-types-hashable.md\">SE-0188 Make Standard Library Index Types Hashable<\/a><\/li><li><a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/master\/proposals\/0191-eliminate-indexdistance.md\">SE-0191 Eliminate IndexDistance from Collection<\/a><\/li><\/ul><p>[&#8230;]<\/p><p>These are additional Swift Evolution proposals that were implemented in this release:<\/p><ul><li><a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/master\/proposals\/0184-unsafe-pointers-add-missing.md\">SE-0184 Unsafe[Mutable][Raw][Buffer]Pointer: add missing methods, adjust existing labels for clarity, and remove deallocation size<\/a><\/li><li><a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/master\/proposals\/0186-remove-ownership-keyword-support-in-protocols.md\">SE-0186 Remove ownership keyword support in protocols<\/a><\/li><li><a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/master\/proposals\/0189-restrict-cross-module-struct-initializers.md\">SE-0189 Restrict Cross-module Struct Initializers<\/a><\/li><li><a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/master\/proposals\/0198-playground-quicklook-api-revamp.md\">SE-0198 Playground QuickLook API Revamp<\/a><\/li><\/ul><\/blockquote>\n<p>This was a fun update because it was easy to update my code, and I was able to delete lots of boilerplate related to <code>Equatable<\/code> and <code>IndexDistance<\/code>. Synthesized <code>Equatable<\/code> and <code>Hashable<\/code> conformance makes the code much more concise and potentially more reliable. It still has some room for improvement, though: there&rsquo;s no way to omit fields without implementing the methods yourself, and the <a href=\"https:\/\/github.com\/apple\/swift\/blob\/a7ff0da33488b9050cf83df95f46e5b9aa2348d5\/stdlib\/public\/core\/Hashing.swift#L146\">internal function<\/a> for <a href=\"https:\/\/stackoverflow.com\/questions\/42627014\/implementing-a-hash-combiner-in-swift\">combining hash values<\/a> is not exposed as API.<\/p>\n\n<p>See also: <a href=\"https:\/\/useyourloaf.com\/blog\/replacing-flatmap-with-compactmap\/\">Replacing flatMap With compactMap<\/a>.<\/p>\n\n<p>Previously: <a href=\"https:\/\/mjtsai.com\/blog\/2017\/08\/22\/swift-4-synthesizing-equatable-and-hashable-conformance\/\">Swift 4: Synthesizing Equatable and Hashable Conformance<\/a>, <a href=\"https:\/\/mjtsai.com\/blog\/2018\/03\/13\/swift-4-1-conditional-conformance-is-amazing\/\">Swift 4.1 Conditional Conformance Is Amazing<\/a>, <a href=\"https:\/\/mjtsai.com\/blog\/2018\/02\/28\/code-size-optimization-mode-in-swift-4-1\/\">Code Size Optimization Mode in Swift 4.1<\/a>.<\/p>\n\n<p>Update (2018-04-03): <a href=\"https:\/\/twitter.com\/AirspeedSwift\/status\/980934657918185474\">Ben Cohen<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/AirspeedSwift\/status\/980934657918185474\"><p>Hashing needed some more work before this could happen, but @lorentey has been working on a proposal to turn the hashing improvements he landed in 4.2 into a <a href=\"https:\/\/github.com\/apple\/swift-evolution\/pull\/821\">proposal for a public API<\/a>.<\/p><\/blockquote>\n\n<p>See also: <a href=\"https:\/\/mjtsai.com\/blog\/2016\/12\/09\/accidentally-quadratic-rust-hash-tables\/\">Accidentally Quadratic Rust Hash Tables<\/a>.<\/p>\n\n<p>Update (2018-04-12): <a href=\"https:\/\/forums.swift.org\/t\/se-0206-hashable-enhancements\/11675\/103\">Joe Groff<\/a> (<a href=\"https:\/\/twitter.com\/jckarter\/status\/984176970731700224\">tweet<\/a>):<\/p>\n<blockquote cite=\"https:\/\/forums.swift.org\/t\/se-0206-hashable-enhancements\/11675\/103\"><p>The core team discussed this proposal in our meeting today. There are still a couple days left in the review period, but we&rsquo;re tentatively inclined to accept this proposal, but wanted to suggest some changes based on public review discussion and our own review[&#8230;]<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Ted Kremenek: Swift 4.1 adds more generics features to the language, furthering the goals set out in the Swift Generics Manifesto. The following generics-related proposals have been implemented in this release:SE-0143 Conditional ConformanceSE-0157 Support recursive constraints on associated typesSE-0185 Synthesizing Equatable and Hashable conformanceSE-0187 Introduce Sequence.compactMap(_:)SE-0188 Make Standard Library Index Types HashableSE-0191 Eliminate IndexDistance from [&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":"2018-04-12T01:13:30Z","apple_news_api_id":"992c232b-661a-4616-96ac-d6b5566d1cdb","apple_news_api_modified_at":"2018-04-12T17:41:09Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAA==","apple_news_api_share_url":"https:\/\/apple.news\/AmSwjK2YaRhaWrNa1Vm0c2w","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-21029","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\/21029","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=21029"}],"version-history":[{"count":3,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/21029\/revisions"}],"predecessor-version":[{"id":21219,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/21029\/revisions\/21219"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=21029"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=21029"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=21029"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}