6

I have a user-defined variable in my Xcode project - MY_VARIABLE:
enter image description here I linked MY_VARIABLE also in my .plist file:
enter image description here And then I use it in my code:
NSString *myVariable = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"MY_VARIABLE"];

In the fastfile I have my AppStore lane and, only in that case, I would like to change the value of MY_VARIABLE.

I'm currently using:
ENV["MY_VARIABLE"] = "appStoreValue"
but this doesn't work.

tagyro
  • 1,638
  • 2
  • 21
  • 36

2 Answers2

5

After a bit of research I found a solution to this.
I'm using xcargs in the gym action, like:

gym(
  scheme: "MyScheme",
  configuration: "Release",
  use_legacy_build_api: 1,
  xcargs: "MY_VARIABLE=appStoreValue"
)
tagyro
  • 1,638
  • 2
  • 21
  • 36
1

Thx to https://stackoverflow.com/a/56179405/5790492 and https://nshipster.com/xcconfig/
I've created the xcconfig file, added it to project in Info tab. For fastlane added this plugin to work with xcconfig. And now it looks like:

def bumpMinorVersionNumber
    currentVersion = get_xcconfig_value(path: 'fastlane/VersionsConfig.xcconfig',
                                        name: 'FC_VERSION')
    versionArray = currentVersion.split(".").map(&:to_i)
    versionArray[2] = (versionArray[2] || 0) + 1
    newVersion = versionArray.join(".")
    update_xcconfig_value(path: 'fastlane/VersionsConfig.xcconfig',
                          name: 'FC_VERSION',
                          value: newVersion.to_s)
    UI.important("Old version: #{currentVersion}. Version bumped to: #{newVersion}")
end

def bumpBuildNumber
    currentBuildNumber = get_xcconfig_value(path: 'fastlane/VersionsConfig.xcconfig',
                                            name: 'FC_BUILD')
    newBuildNumber = currentBuildNumber.to_i + 1
    update_xcconfig_value(path: 'fastlane/VersionsConfig.xcconfig',
                          name: 'FC_BUILD',
                          value: newBuildNumber.to_s)
    UI.important("Old build number: #{currentBuildNumber}. Build number bumped to: #{newBuildNumber}")
end

enter image description here

Nike Kov
  • 12,630
  • 8
  • 75
  • 122