How do I set Scripting Define Symbols In Xcode from Unity?

This question was asked in 2017 with no movement. I’ve been unable to find any resources on the topic. So I apologize for the duplication.

As I commented in the old thread. I currently have a bunch of code in c#, swift, and c that rely all on the same preprocessor being defined. It seems silly and error prone to have to manually go into XCode and set the build flags again. I don’t have these issue on Android build.

Is there a way from Unity, programmatically, to take the pre defined preprocessor macro, which I set in Unity with this static method,

	private static void SetBuildMacroForGroup(BuildTargetGroup group, string buildMacro) {
		PlayerSettings.GetScriptingDefineSymbolsForGroup(group, out var macros);
		if (macros.Any(macro => macro == buildMacro)) {
			return;
		}

		var enumerable = macros.Append(buildMacro);
		PlayerSettings.SetScriptingDefineSymbolsForGroup(group, enumerable.ToArray());
	}

and ensure that the same macro ends up as a build macro in xcode so that iOS plugin files only compile certain code if and only if the macro is defined, exactly how it works inside the Unity Engine?

It turns out you can forward Unity Macros along to xcode in this way

public static void OnPostprocessBuild(BuildTarget target, string path) {
    var pbx = new PBXProject();
    var pbxPath = PBXProject.GetPBXProjectPath(path);
    pbx.ReadFromFile(pbxPath);

      // UNITY MACRO
     #if EXAMPLE_UNITY_BUILD_FLAG
          var projectGuid = pbx.ProjectGuid();
          
          // Enable MACRO for Swift code
          pbx.SetBuildProperty(projectGuid, "SWIFT_ACTIVE_COMPILATION_CONDITIONS", "EXAMPLE_UNITY_BUILD_FLAG");
          
          // Enable MACRO for C++ code
          pbx.SetBuildProperty(projectGuid, "GCC_PREPROCESSOR_DEFINITIONS", "EXAMPLE_UNITY_BUILD_FLAG");
    #endif
}