{"id":32849,"date":"2021-06-14T16:34:19","date_gmt":"2021-06-14T20:34:19","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=32849"},"modified":"2022-05-05T13:47:30","modified_gmt":"2022-05-05T17:47:30","slug":"swift-overloads-that-differ-only-in-async","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2021\/06\/14\/swift-overloads-that-differ-only-in-async\/","title":{"rendered":"Swift Overloads That Differ Only in Async"},"content":{"rendered":"<p><a href=\"https:\/\/forums.swift.org\/t\/async-feedback-overloads-that-differ-only-in-async\/49573\">Gwendal Rou&eacute;<\/a>:<\/p>\n<blockquote cite=\"https:\/\/forums.swift.org\/t\/async-feedback-overloads-that-differ-only-in-async\/49573\"><p>I wish users could use the same method names in both synchronous and asynchronous contexts.<\/p><p>[&#8230;]<\/p><p>But I face &ldquo;Invalid redeclaration&rdquo; compiler errors, as expected according to the proposal.<\/p><p>[&#8230;]<\/p><p>Should I rename my async variants with some funny name? <code>await asyncRead()<\/code>? But the proposal itself wants to avoid <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/csharp\/programming-guide\/concepts\/async\/task-asynchronous-programming-model\">C#&rsquo;s pervasive Async suffix<\/a>.<\/p><p>[&#8230;]<\/p><p>[The] new Core Data apis described in the WWDC21 conference <a href=\"https:\/\/developer.apple.com\/wwdc21\/10017\">Bring Core Data concurrency to Swift and SwiftUI<\/a> face the same problem. They worked around the overload error by defining async methods with a different signature[&#8230;]<\/p><\/blockquote>\n\n<p>He found a <a href=\"https:\/\/forums.swift.org\/t\/async-feedback-overloads-that-differ-only-in-async\/49573\/3\">workaround<\/a> using the non-public <code>@_disfavoredOverload<\/code> attribute.<\/p>\n\n<p><a href=\"https:\/\/forums.swift.org\/t\/async-feedback-overloads-that-differ-only-in-async\/49573\/4\">Ben Trumbull<\/a>:<\/p>\n<blockquote cite=\"https:\/\/forums.swift.org\/t\/async-feedback-overloads-that-differ-only-in-async\/49573\/4\">\n<p>Methods in the same module cannot overload only on <code>async<\/code>-ness, but methods bridged from ObjC or in a different Swift module may.<\/p>\n<\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2020\/12\/11\/swift-concurrency-interoperability-with-objective-c\/\">Swift Concurrency Interoperability With Objective-C<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2020\/12\/07\/swift-proposal-for-async-await\/\">Swift Proposal for async\/await<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Gwendal Rou&eacute;: I wish users could use the same method names in both synchronous and asynchronous contexts.[&#8230;]But I face &ldquo;Invalid redeclaration&rdquo; compiler errors, as expected according to the proposal.[&#8230;]Should I rename my async variants with some funny name? await asyncRead()? But the proposal itself wants to avoid C#&rsquo;s pervasive Async suffix.[&#8230;][The] new Core Data apis [&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":"2021-06-14T20:34:23Z","apple_news_api_id":"27a98cda-bd2c-4e83-bb5e-97dfa4dc7c5b","apple_news_api_modified_at":"2022-05-05T17:47:43Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAA==","apple_news_api_share_url":"https:\/\/apple.news\/AJ6mM2r0sToO7XpffpNx8Ww","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":[800,109,1412,31,2078,46,30,2077,54,71,2200,901],"class_list":["post-32849","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-concurrency","tag-coredata","tag-grdb","tag-ios","tag-ios-15","tag-languagedesign","tag-mac","tag-macos-12","tag-objective-c","tag-programming","tag-swift-concurrency","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/32849","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=32849"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/32849\/revisions"}],"predecessor-version":[{"id":32850,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/32849\/revisions\/32850"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=32849"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=32849"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=32849"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}