{"id":39071,"date":"2023-04-17T16:15:55","date_gmt":"2023-04-17T20:15:55","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=39071"},"modified":"2023-04-17T16:15:55","modified_gmt":"2023-04-17T20:15:55","slug":"swifts-versioned-canimport","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2023\/04\/17\/swifts-versioned-canimport\/","title":{"rendered":"Swift&rsquo;s Versioned canImport()"},"content":{"rendered":"<p><a href=\"https:\/\/blog.eidinger.info\/sdk-conditional-code-with-canimportmodule-version-1234\">Marco Eidinger<\/a>:<\/p>\n<blockquote cite=\"https:\/\/blog.eidinger.info\/sdk-conditional-code-with-canimportmodule-version-1234\"><p><a href=\"https:\/\/developer.apple.com\/documentation\/swiftui\/font\/width(_:)\">SwiftUI.Font.width(_:)<\/a> was actually introduced in iOS 16.1 and not in iOS 16.0 as the documentation suggests.<\/p><p>[&#8230;]<\/p><p>While researching a solution, I stumbled on an interesting fact that <code>#if canImport<\/code> allows specifying a version that gets checked during compile-time. The version gets compared against the <code>-user-module-version<\/code> flag in the <code>.swiftmodule<\/code> file using.<\/p><p>[&#8230;]<\/p><p>Suppose the framework and the APIs in question are cross-platform. In that case, you can (theoretically) write a single query to determine the build time availability of the API across multiple platforms because module versions tend to be aligned across the aligned platform-specific SDKs.<\/p><p>It allows you to gracefully handle things like APIs introduced midway through the betas even though the overall system\/SDK version number hasn&rsquo;t changed.<\/p><\/blockquote>\n<p>But you have to figure out the <code>user-module-version<\/code> of the framework.<\/p>","protected":false},"excerpt":{"rendered":"<p>Marco Eidinger: SwiftUI.Font.width(_:) was actually introduced in iOS 16.1 and not in iOS 16.0 as the documentation suggests.[&#8230;]While researching a solution, I stumbled on an interesting fact that #if canImport allows specifying a version that gets checked during compile-time. The version gets compared against the -user-module-version flag in the .swiftmodule file using.[&#8230;]Suppose the framework and [&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":"2023-04-17T20:15:58Z","apple_news_api_id":"e65184d5-29de-4a46-947d-299e5f2b2812","apple_news_api_modified_at":"2023-04-17T20:15:58Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/A5lGE1SneSkaUfSmeXysoEg","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":[31,2185,475,2223,71,901,1812],"class_list":["post-39071","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-ios","tag-ios-16","tag-mavericks","tag-macos-13-ventura","tag-programming","tag-swift-programming-language","tag-swiftui"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/39071","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=39071"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/39071\/revisions"}],"predecessor-version":[{"id":39072,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/39071\/revisions\/39072"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=39071"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=39071"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=39071"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}