1

I'd like to use the same .xcconfig files for my Xcode projects so that I automatically have the same warning settings across all my projects. I would love to create e.g. a Cocoapod which I include via Podfile and then copy the config files over or reference them from within my Xcode project.

Is there a way to achieve this?

swalkner
  • 16,679
  • 31
  • 123
  • 210

2 Answers2

2

Requirements

As far as I understand your requirements are:

  • Download xcconfig files, e.g., Cocoapods, GitHub
  • Set xcconfig files on the Xcodeproj for each configuration on project and target level

Potential solution

As far as I know it is impossible to run a script from a Cocoapod to manipulate the including Xcode project. Fortunately, the guys from Cocoapods provide a Ruby gem called xcodeproj to manipulate Xcode projects and workspaces including build settings.

I have been using this gem to develop a tool (phoenx) to automate the generation of Xcode projects and workspaces based on metadata files (much like Podfiles). I have extracted the relevant code parts into a new ruby gem called xcconfig.

Xcconfig

Xcconfig can download and configure the xcconfig files on any Xcode project file. A Configfile specifies the source of the configuration files (optional) and how to apply those xcconfig files to your project. If the files are not part of the project it will add them (together with groups for the subfolders) and configure the project accordingly. If you change the xcconfig files in your global repository you just need to run xcconfig again to sync your repositories.

The Configfile should reside in the same folder as you xcodeproj file (just like the Podfile).

# Specify where to download the config files (optional)
source "git@github.com:xyz/Configuration"

# Specify the name of the project, e.g., MyProject if your project file is MyProject.xcodeproj
Project.new "MyProject" do |project|

    # Specify xcconfig files for each configuration on project level (paths are relative t
    project.config_files["Release"] = "Configuration/project_release.xcconfig"
    project.config_files["Debug"] = "Configuration/project_debug.xcconfig"

    # Specify target and xcconfig files for each configuration
    project.target "test" do |target|

        target.config_files["Debug"] = "Configuration/debug.xcconfig"

    end

end

You can integrate this gem with cocoapods or use it standalone. If you want to give it a try you can install it with sudo gem install xcconfig and then run xcconfig in your project directory with the Configfile. The sources are available on my GitHub account.

Hope that helps.

Jens Meder
  • 4,237
  • 1
  • 25
  • 25
0

You can create a custom project template and put a file named ___FILEBASENAME___.xcconfig with the desired settings inside your .xctemplate bundle. Then you can choose this template while creating a new project and it will automatically have the default settings you specified.

bzz
  • 5,556
  • 24
  • 26