As an iOS developer, we work with Xcode Project every day, and if we use Cocoapods to manage third-party libraries, then xcWorkspace. Today, we’ll take a look at these two files from a content format perspective

Pbxproj and xcworkspace

xcode project

The Apple documentation describes the project file as follows:

Xcode Project contains all the files, resources, and compilation Settings required by the software, including the previous dependencies of these files. It contains one or more targets, which describe how to compile. The project file defines how to compile each target.Copy the code

In the ***.xcodeProj file, display the package contents, we can find the project. Pbxproj file, open the file

/ /! $*UTF8*$! { archiveVersion = 1; classes = { }; objectVersion = 51; objects = { }; rootObject = AD5BA36126F07D6B00BBB9AF /* Project object */; }Copy the code
  • archiveVersion: The value is always 1, andclassesThe field value is always empty.
  • objectVersion: This represents the presentXcodeVersion.
  • rootObjectIs the most important onekey.pbxprojIt’s a tree structure,rootObjectIs its root node, and its value is oneidentifier, pointing to aPXBProjectObject, that’s what we useXcodeObject.

xcworkspace

Workspace is an Xcode document that groups projects and other documents so they can be worked on together. A workspace contains one or more Xcode projects and other files that you want to include for processing. The workspace structure is as follows:

<? The XML version = "1.0" encoding = "utf-8"? > <Workspace version = "1.0"> <FileRef location = "group: hqpdemo. xcodeProj "> </FileRef> <FileRef location = "group:Pods/Pods.xcodeproj"> </FileRef> </Workspace>Copy the code

This workSPce contains two XCodeProJ objects. Location stores the relative path of the file.

Xcode Objects

Xcode Object identifiers

All Objects have a unique identifier, such as rootObject = AD5BA36126F07D6B00BBB9AF, which is used to find the corresponding value in the project file. In the project file, we can find this object:

AD5BA36126F07D6B00BBB9AF /* Project object */ = { isa = PBXProject; attributes = { LastSwiftUpdateCheck = 1250; LastUpgradeCheck = 1250; TargetAttributes = {AD5BA36826F07D6B00BBB9AF = {CreatedOnToolsVersion = 12.5.1; }; AD5BA37E26F07D7000BBB9AF = {CreatedOnToolsVersion = 12.5.1; TestTargetID = AD5BA36826F07D6B00BBB9AF; }; AD5BA38926F07D7000BBB9AF = {CreatedOnToolsVersion = 12.5.1; TestTargetID = AD5BA36826F07D6B00BBB9AF; }; }; }; buildConfigurationList = AD5BA36426F07D6B00BBB9AF /* Build configuration list for PBXProject "HQPDemo" */; CompatibilityVersion = "Xcode 9.3"; developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en,Base ); mainGroup = AD5BA36026F07D6B00BBB9AF; productRefGroup = AD5BA36A26F07D6B00BBB9AF /* Products */; projectDirPath = ""; projectRoot = ""; targets = ( AD5BA36826F07D6B00BBB9AF /* HQPDemo */, AD5BA37E26F07D7000BBB9AF /* HQPDemoTests */, AD5BA38926F07D7000BBB9AF /* HQPDemoUITests */, ); };Copy the code

PBXProject

RootObject points to an instance of PBXObject.

  • BuildConfigurationList points to the XCConfigurationList object, and usually a project has both Debug and Release configurations.

  • The mainGroup points to the PBXGroup object, which is a collection that contains all the files compiled by the project.

AD5BA36026F07D6B00BBB9AF = {
    isa = PBXGroup;
    children = (
        AD5BA36B26F07D6B00BBB9AF /* HQPDemo */,
        AD5BA38226F07D7000BBB9AF /* HQPDemoTests */,
        AD5BA38D26F07D7000BBB9AF /* HQPDemoUITests */,
        AD5BA36A26F07D6B00BBB9AF /* Products */,
        BB80D1A639BC424ACD0B0514 /* Pods */,
        66A61A52D7288E9C33A3B97A /* Frameworks */,
    );
    sourceTree = "<group>";
};
Copy the code
  • targetsIs a collection of all the targets included in the project. Each taget isPBXNativeTargetObject,

PBXGroup

A PBXGroup object is a collection of one or more objects.

  • PBXFileReference: is a collection containing file references, which can beSource files, framework files, binaries, or other project files.
  • PBXReferenceProxy: A collection of references outside the project, usually used when a dependent project needs to be referenced.
  • PBXGroupA:groupCan contain othergroupIn theUIThe form shown inA folder.

PBXFilereference

All objects are defined as PBXFilereference objects.

2B64ADE26330B6773355D9FA /* Pods_HQPDemoTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_HQPDemoTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };

3D84B89EBA3CA1C9B9C8C4B4 /* Pods-HQPDemo-HQPDemoUITests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HQPDemo-HQPDemoUITests.debug.xcconfig"; path = "Target Support Files/Pods-HQPDemo-HQPDemoUITests/Pods-HQPDemo-HQPDemoUITests.debug.xcconfig"; sourceTree = "<group>"; };
Copy the code
  • SourceTree is the path of the physical object.

    indicates the group to which the PBXFilereference object belongs. In the case of project itself, the sourceTree value is BUILT_PRODUCTS_DIR.

  • LastKnownFileType indicates the type of the source file, and sourcecode.swift indicates that the file is swift

xcconfig: text.xcconfig
swift   : sourcecode.swift
xcassets: folder.assetcatalog
plist   : text.plist.xml
Copy the code
  • explicitFileTypeRepresents the object to build, for example
AD5BA36926F07D6B00BBB9AF /* HQPDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HQPDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
Copy the code

You need to build it as an app file at build time.

PBXNativeTarget

The PBXNativeTarget object describes how to build a target

AD5BA36826F07D6B00BBB9AF /* HQPDemo */ = {
    isa = PBXNativeTarget;
    buildConfigurationList = AD5BA39326F07D7000BBB9AF /* Build
    configuration list for PBXNativeTarget "HQPDemo" */;
    buildPhases = (
        F854D8F9C862E74399020DEA /* [CP] Check Pods Manifest.lock */,
        AD5BA36526F07D6B00BBB9AF /* Sources */,
        AD5BA36626F07D6B00BBB9AF /* Frameworks */,
        AD5BA36726F07D6B00BBB9AF /* Resources */,
        AB27C9DC0F1571380994A639 /* [CP] Embed Pods Frameworks */,
    );
    buildRules = ();
    dependencies = ();
    name = HQPDemo;
    productName = HQPDemo;
    productReference = AD5BA36926F07D6B00BBB9AF /* HQPDemo.app */;
    productType = "com.apple.product-type.application";
};
Copy the code

BuildPhase is represented in Xcode as shown in the figure below, which corresponds one-to-one to the buildPhases steps.

ProductReference value is

AD5BA36926F07D6B00BBB9AF /* HQPDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HQPDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
Copy the code

Indicates that it is an executable binary file. The PBXNativeTarget object has its own buildConfigurationList

PBXBuildPhase

There are seven different types of PBXBuildPhase:

  • PBXAppleScriptBuildPhase: Run the Apple script.
  • PBXCopyFilesBuildPhase: Copies files.
  • PBXFrameworksBuildPhaseLinks:frameworkFile.
  • PBXHeadersBuildPhase: compiled header file.
  • PBXResourcesBuildPhase: Resource file.
  • PBXShellScriptBuildPhase: performsh shellThe script.
  • PBXSourcesBuildPhase: compiled source file.

For our purposes, our focus should be on the PBXSourcesBuildPhase object

PBXSourcesBuildPhase

AD5BA36526F07D6B00BBB9AF /* Sources */ = {
    isa = PBXSourcesBuildPhase;
    buildActionMask = 2147483647;
    files = (
        AD5BA37126F07D6B00BBB9AF /* ViewController.swift in Sources */,
        AD5BA36D26F07D6B00BBB9AF /* AppDelegate.swift in Sources */,
        AD5BA36F26F07D6B00BBB9AF /* SceneDelegate.swift in Sources */,
        );
        runOnlyForDeploymentPostprocessing = 0;
};
Copy the code

It is an entry point to the collection of source files that need to be compiled (PBXBuildFile), where all three source files are compiled, as shown in the following figure in Xcode.

PBXBuildFile

PBXBuildFile is the core of the Xcode build file. PBXBuildFile is associated with PBXFileReference.

AD5BA36F26F07D6B00BBB9AF /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD5BA36E26F07D6B00BBB9AF /* SceneDelegate.swift */; };
Copy the code
AD5BA36E26F07D6B00BBB9AF /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Copy the code

LastKnownFileType specifies the type of the source file. File types are summarized briefly in PBXFilereference.

Through the above content, we have made an overall introduction to XcodeProj files, hoping to have a further understanding of Xcode project files through this article. The xcodeprojGem library is used to modify project files in Cocoapods. By understanding the engineering structure, we can better do some engineering automation operations.

Reference article:

Xcode – xcworkspace and xcodeproj

PBXProj Identifiers

A dive into Xcode projects and workspaces