Property wrapper that allows you to access build settings values through the infoDictionary
property of Foundation’s Bundle
API.
Create a build configuration file i.e Development.xcconfig
:
HOST = localhost
TIMEOUT = 15.0
In your Info.plist
you can reference build settings values using the following syntax $(BUILD_SETTING_NAME)
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>HOST</key>
<string>$(HOST)</string>
<key>TIMEOUT</key>
<string>$(TIMEOUT)</string>
</dict>
</plist>
For example, adding @XcodeConfig
like this:
enum API {
@XcodeConfig(key: "HOST")
static var host: String
@XcodeConfig(key: "TIMEOUT")
static var timeout: TimeInterval
}
will access build settings values: "localhost"
and 15.0
which are defined in Development.xcconfig
.
To integrate XcodeConfig into your Xcode project using CocoaPods, specify it in your Podfile
:
pod 'XcodeConfig', :git => 'https://github.com/AnasAlhasani/XcodeConfig'
Then, run the following command:
$ pod install
To integrate XcodeConfig into your Xcode project using Swift Package Manager, add it to the dependencies
value of your Package.swift
:
dependencies: [
.package(url: "https://github.com/AnasAlhasani/XcodeConfig.git", from: "1.0.1")
]
Anas Alhasani