{"id":387,"date":"2022-04-04T04:43:16","date_gmt":"2022-04-04T04:43:16","guid":{"rendered":"https:\/\/ootips.org\/yonat\/?p=387"},"modified":"2022-09-06T06:49:30","modified_gmt":"2022-09-06T06:49:30","slug":"getting-your-framework-version-in-run-time","status":"publish","type":"post","link":"https:\/\/ootips.org\/yonat\/getting-your-framework-version-in-run-time\/","title":{"rendered":"Getting your framework version in run-time"},"content":{"rendered":"\n<p>Xcode 13 introduced a new behavior that breaks framework versions: When your clients upload their app, Apple changes the <tt><code>CFBundleShortVersionString<\/code><\/tt> of all frameworks to match that of the app.<br>(See <a rel=\"noopener\" href=\"https:\/\/stackoverflow.com\/questions\/68237292\/manage-version-and-build-number\" target=\"_blank\">this StackOverflow thread<\/a> for example)<\/p>\n\n\n\n<p>One way to avoid that is to hard-code your framework version. But if you you want to keep using the <tt><code>MARKETING_VERSION<\/code><\/tt> build setting, you can use the following hack.<\/p>\n\n\n\n<p>Create a version variable for your framework, for example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\npublic class MyFramwork: NSObject {\n    @objc static var version: String = &quot;&quot;\n}\n<\/pre><\/pre>\n\n\n\n<p>Then include this Objective-C file in your framework:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><pre class=\"brush: objc; title: ; notranslate\" title=\"\">\n#import &amp;lt;MyFramwork\/MyFramwork-swift.h&gt;\n\n#define PROCESSOR_STRING(x) PRE_PROCESSOR_STRING_LITERAL(x)\n#define PRE_PROCESSOR_STRING_LITERAL(x) @#x\n\n@interface MyFramwork(version)\n@property (class) NSString *version; \/\/ to access internal property\n@end;\n\n@interface MyFramworkLoader: NSObject\n@end\n\n@implementation MyFramworkLoader\n\n#ifdef MARKETING_VERSION\n+ (void)load {\n    dispatch_async(dispatch_get_main_queue(), ^{\n        MyFramwork.version = PROCESSOR_STRING(MARKETING_VERSION);\n    });\n}\n#endif\n\n@end\n<\/pre><\/pre>\n\n\n\n<p>This will assign the <code>MARKETING_VERSION<\/code> value that you built you framework with, instead of an Apple-manipulated <code>CFBundleShortVersionString<\/code> value.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Xcode 13 introduced a new behavior that breaks framework versions: When your clients upload their app, Apple changes the CFBundleShortVersionString of all frameworks to match that of the app.(See this StackOverflow thread for example) One way to avoid that is &hellip; <a href=\"https:\/\/ootips.org\/yonat\/getting-your-framework-version-in-run-time\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[1],"tags":[7,6,13,14,17,16],"class_list":["post-387","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-ios","tag-iphone","tag-objective-c","tag-sample-code","tag-swift","tag-workaround"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2aEUP-6f","_links":{"self":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts\/387","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/comments?post=387"}],"version-history":[{"count":12,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts\/387\/revisions"}],"predecessor-version":[{"id":429,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts\/387\/revisions\/429"}],"wp:attachment":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/media?parent=387"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/categories?post=387"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/tags?post=387"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}