xcproj is a library written in Swift for parsing and working with Xcode projects. It's heavily inspired in CocoaPods XcodeProj and xcode.
Being able to write command line scripts in Swift to update your Xcode projects configuration. Here you have some examples:
- Add new
Build phases
. - Update the project
Build Settings
. - Create new
Schemes
.
Project | Description |
---|---|
XcodeGen | Generate Xcode projects dynamically from a YAML file |
xclint | Lint the format of your Xcode projects |
xctools | Handy command line tools |
- Git clone the repository
[email protected]:xcodeswift/xcproj.git
. - Generate xcproj with
swift package generate-xcodeproj
. - Open
xcproj.xcodeproj
.
Add the dependency in your Package.swift
file:
let package = Package(
name: "myproject",
dependencies: [
.package(url: "https://github.com/xcodeswift/xcproj.git", .upToNextMajor(from: "0.2.0")),
],
targets: [
.target(
name: "myproject",
dependencies: ["xcproj"]),
]
)
Using Marathon
Edit your Marathonfile
and specify the dependency in there:
https://github.com/xcodeswift/xcproj.git
Using CocoaPods
Edit your Podfile
and specify the dependency:
pod "xcproj"
Using Carthage
Edit your Cartfile
and specify the dependency:
github "xcodeswift/xcproj"
Note: xcproj is only available for macOS and iOS projects.
Xcode provides models that represent Xcode projects and are initialized by parsing the content from your project files. The generated models are classes that can be mutated at any time. These mutations in the models are kept in memory until they are persisted by writing them back to disk by writing either the XcodeProj
or the XCWorkspace
model. Modifications in your projects are usually executed in three steps:
- Read the project or workspace initializing a
XcodeProj
or aXCWorkspace
object respectively. - Modify those objects or any of its dependencies.
- Write it back to disk.
// Removing all frameworks build phases
let project = try! XcodeProj(path: "myproject.xcodeproj")
project.pbxproj.frameworksBuildPhases.removeAll()
try! project.write(path: "myproject.xcodeproj")
The diagram below shows the sructure of a Xcode project.
A XcodeProj
has the following properties:
XCSharedData
that contains the information about the schemes of the project.XCWorkspace
that defines the structure of the project workspace.PBXProj
that defines the strcuture of the project.
Amongt other properties, the most important one in the PBXProj
object is Objects
. Projects are defined by a list of those objects that can be classified in the following groups:
- Build phases objects: Define the available build phases.
- Targets objects: Define your project targets and dependencies between them.
- Configuration objects: Define the available configs and the link between them and the targets.
- Files objects: Define the project files, build files and groups.
All objects subclass PBXObject
, and have an unique & deterministic reference. Moreover, they are hashable and conform the Equatable
protocol.
You can read more about what each of these objects is for on the following link
- Objects references are used to define dependencies between objects. In the future we might rather use objects references instead of the unique identifier.
- The write doesn't validate the structure of the project. It's up to the developer to validate the changes that have been done using
xcproj
. - New versions of Xcode might introduce new models or property that are not supported by
xcproj
. If you find any, don't hesitate to open an issue on the repository.
You can check out the documentation on the following link. The documentation is automatically generated in every release by using Jazzy from Realm.
- PathKit
- Xcode Project File Format
- A brief look at the Xcode project format
- pbexplorer
- pbxproj identifiers
- mob-pbxproj
- Xcodeproj
- Nanaimo
- Facebook Buck
- Swift Package Manager - Xcodeproj
This project exists thanks to all the people who contribute. [Contribute].
Thank you to all our backers! π [Become a backer]
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]
MIT License
Copyright (c) 2017 swift-code
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.