xcode工程文件格式(Xcode Project File Format)详解

  • Post author:
  • Post category:其他


The Xcode project file is an old-style plist (Next style) based on braces to delimit the hierarchy. The file begins with an 
explicit encoding information, usually the UTF-8 one. This means that the file must not bear a BOM (Byte Ordering Mark) at its 
start or the parsing will fail.

xcode工程文件是一种旧式风格的plist文件(基于括号来界定配置内容层级结构)。project.pbxproj以一个显式的编码信息开头,通常为UTF-8编码,如下:

// !$*UTF8*$!

这样也意味着该文件不能以BOM字符开头,否则会解析失败。如果解析失败,可以通过vim、vi命令打开文件,查看是文件是否以BOM字符开头。



A brief look at the Xcode project format




简单的来看下xcode 工程文件结构(粗字体是测试工程里面有的配置,下面也就有的部分进行分享):




Elements:




Here is the list of elements contained in the file format:
Root Element
<strong>PBXBuildFile</strong>
<strong>PBXReferenceProxy</strong>
PBXBuildPhase
PBXAppleScriptBuildPhase
PBXCopyFilesBuildPhase
<strong>PBXFrameworksBuildPhase</strong>
PBXHeadersBuildPhase
<strong>PBXResourcesBuildPhase
PBXShellScriptBuildPhase
PBXSourcesBuildPhase
PBXContainerItemProxy</strong>
PBXFileElement
<strong>PBXFileReference
PBXGroup
PBXVariantGroup</strong>
PBXTarget
PBXAggregateTarget
PBXLegacyTarget
<strong>PBXNativeTarget
PBXProject
PBXTargetDependency
XCBuildConfiguration
XCConfigurationList</strong>
<strong>XCVersionGroup
</strong>

Root Element

Attribute Type Value Comment
archiveVersion Number 1 Default value.
classes List Empty
objectVersion Number See XcodeCompatibilityVersion enumeration.
objects Map A map of element The map is indexed by the elements identifier.
rootObject Reference An element reference The object is a reference to a PBXProject element.

小片段,格式有点像json,但是又不一样:

// !$*UTF8*$!
{
    archiveVersion = 1;
    classes = {
    };
    objectVersion = 45;
    objects = {

    ...

    };
    rootObject = 0867D690FE84028FC02AAC07 /* Project object */;
}

其中,objects是最主要的配置,包含N多信息。

PBXContainerItemProxy

This is the element for to decorate a target item.

部署target的元素

Attribute Type Value Comment
reference UUID A 96 bits identifier
isa PBXContainerItemProxy Empty
containerPortal Reference An element reference The object is a reference to a PBXProject element.
proxyType Number 1
remoteGlobalIDString Reference An element reference A unique reference ID.
remoteInfo String

PBXContainerItemProxy包含了若干个上述元素,片段:

                035703AE18EABAF4004B160A /* PBXContainerItemProxy */ = {
                        isa = PBXContainerItemProxy;
                        containerPortal = B1E8252217CCADFD00005C6F /* app.xcodeproj */;
                        proxyType = 2;
                        remoteGlobalIDString = 0336F132151729D200EFCD4E;
                        remoteInfo = app;
                };

PBXFileReference

A PBXFileReference is used to track every external file referenced by the project: source files, resource files, libraries, generated application files, and so on.


PBXFileReference用来跟踪被工程引用的外部文件:源文件,库文件,生成的应用文件等等。

Attribute Type Value Comment
reference UUID A 96 bits identifier
isa PBXFileReference Empty
fileEncoding Number See the PBXFileEncoding enumeration.
explicitFileType String See the PBXFileType enumeration.
lastKnownFileType String See the PBXFileType enumeration.
name String The filename.
path String The path to the filename.
sourceTree String See the PBXSourceTree enumeration.
片段:
033A5B4318DEF52F002E3194 /* DemoTitleViewCell.m */ = {
isa = PBXFileReference; 
fileEncoding = 4; 
lastKnownFileType = sourcecode.c.objc; 
name = DemoTitleViewCell.m; 
path = iPhone/Controllers/Demo/Setting/DemoTitleViewCell.m; 
sourceTree = "<group>"; 
};

PBXFrameworksBuildPhase

This is the element for the framewrok link build phase.

Attribute Type Value Comment
reference UUID A 96 bits identifier
isa PBXFrameworksBuildPhase Empty
buildActionMask Number 2^32-1
files List A list of element reference The objects are a reference to a PBXBuildFile element.
runOnlyForDeploymentPostprocessing Number 0

片段:

                6F71FAA51B61E4B2008BBED7 /* Frameworks */ = {
                        isa = PBXFrameworksBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
                                6F71FABB1B61E5F2008BBED7 /* Security.framework in Frameworks */,
                                6F71FABA1B61E5E9008BBED7 /* AdSupport.framework in Frameworks */,
                                6F71FAB91B61E5DE008BBED7 /* Foundation.framework in Frameworks */,
                                6F71FAB81B61E5D8008BBED7 /* CFNetwork.framework in Frameworks */,
                                6F71FAA91B61E4B2008BBED7 /* NotificationCenter.framework in Frameworks */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };

PBXGroup

This is the element to group files or groups.

Attribute Type Value Comment
reference UUID A 96 bits identifier
isa PBXGroup Empty
children List A list of element reference The objects are a reference to a PBXFileElement element.
name String The filename.
sourceTree String See the PBXSourceTree enumeration.

代码片段:

                0F2C30081A43534DG00615725 /* dataBase */ = {
                        isa = PBXGroup;
                        children = (
                                0F2C30091A37E67700615725 /* DataBaseManager.h */,
                                0F2C300A1A37E67700615725 /* DataBaseManager.m */,
                                0F2C300B1A37E67700615725 /* demoData.sqlite */,
                        );
                        name = dataBase;
                        path = iPhone/Controllers/dataBase;
                        sourceTree = "<group>";
                };

PBXHeadersBuildPhase

This is the element for the framewrok link build phase.

Attribute Type Value Comment
reference UUID A 96 bits identifier
isa PBXHeadersBuildPhase Empty
buildActionMask Number 2^32-1
files List A list of element reference The objects are a reference to a PBXBuildFile element.
runOnlyForDeploymentPostprocessing Number 0

Example:

87293EBC1153C114007AFD45 /* Headers */ = {
    isa = PBXHeadersBuildPhase;
    buildActionMask = 2147483647;
    files = (
    );
    runOnlyForDeploymentPostprocessing = 0;
};

PBXLegacyTarget

MISSING

PBXNativeTarget

This is the element for a build target that produces a binary content (application or library).

Attribute Type Value Comment
reference UUID A 96 bits identifier
isa PBXNativeTarget Empty
buildConfigurationList Reference An element reference The object is a reference to a XCConfigurationList element.
buildPhases List A list of element reference The objects are a reference to a PBXBuildPhase element.
dependencies List A list of element reference The objects are a reference to a PBXTargetDependency element.
name String The name of the target.
productInstallPath String The product install path.
productName String The product name.
productReference Reference An element reference The object is a reference to a PBXFileReference element.
productType String See the PBXProductType enumeration.

Example:

8D1107260486CEB800E47090 /* XXX */ = {
    isa = PBXNativeTarget;
    buildConfigurationList = C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "XXX" */;
    buildPhases = (
        8D1107290486CEB800E47090 /* Resources */,
        8D11072C0486CEB800E47090 /* Sources */,
        8D11072E0486CEB800E47090 /* Frameworks */,
    );
    buildRules = (
    );
    dependencies = (
    );
    name = XXX;
    productInstallPath = "$(HOME)/Applications";
    productName = TrackIt;
    productReference = 8D1107320486CEB800E47090 /* XXX.app */;
    productType = "com.apple.product-type.application";
};

PBXProject

This is the element for a build target that produces a binary content (application or library).

Attribute Type Value Comment
reference UUID A 96 bits identifier
isa PBXProject Empty
buildConfigurationList Reference An element reference The object is a reference to a XCConfigurationList element.
compatibilityVersion String A string representation of the XcodeCompatibilityVersion.
developmentRegion String The region of development.
hasScannedForEncodings Number 0 or 1 Whether file encodings have been scanned.
knownRegions List A list of string The known regions for localized files.
mainGroup Reference An element reference The object is a reference to a PBXGroup element.
productRefGroup Reference An element reference The object is a reference to a PBXGroup element.
projectDirPath String The relative path of the project.
projectReferences Array of map Each map in the array contains two keys: ProductGroup and ProjectRef.
projectRoot String The relative root path of the project.
targets List A list of element reference The objects are a reference to a PBXTarget element.

Example:

29B97313FDCFA39411CA2CEA /* Project object */ = {
        isa = PBXProject;
        buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "XXX" */;
        compatibilityVersion = "Xcode 2.4";
        developmentRegion = English;
        hasScannedForEncodings = 1;
        knownRegions = (
                English,
                Japanese,
                French,
                German,
                en,
        );
        mainGroup = 29B97314FDCFA39411CA2CEA /* XXX*/;
        projectDirPath = "";
        projectRoot = "";
        targets = (
             8D1107260486CEB800E47090 /* XXX*/,
        );
};

PBXResourcesBuildPhase

This is the element for the resources copy build phase.

Attribute Type Value Comment
reference UUID A 96 bits identifier
isa PBXResourcesBuildPhase Empty
buildActionMask Number 2^32-1
files List A list of element reference The objects are a reference to a PBXBuildFile element.
runOnlyForDeploymentPostprocessing Number 0

Example:

8D1107290486CEB800E47090 /* Resources */ = {
        isa = PBXResourcesBuildPhase;
        buildActionMask = 2147483647;
        files = (
                535C1E1B10AB6B6300F50231 /* ReadMe.txt in Resources */,
                533B968312721D05005E617D /* Credits.rtf in Resources */,
                533B968412721D05005E617D /* InfoPlist.strings in Resources */,
                533B968512721D05005E617D /* MainMenu.nib in Resources */,
                533B968612721D05005E617D /* TableEdit.nib in Resources */,
                533B968712721D05005E617D /* TestWindow.nib in Resources */,
        );
        runOnlyForDeploymentPostprocessing = 0;
};

PBXShellScriptBuildPhase

This is the element for the resources copy build phase.

Attribute Type Value Comment
reference UUID A 96 bits identifier
isa PBXShellScriptBuildPhase Empty
buildActionMask Number 2^32-1
files List A list of element reference The objects are a reference to a PBXBuildFile element.
inputPaths List A list of string The input paths.
outputPaths List A list of string The output paths.
runOnlyForDeploymentPostprocessing Number 0
shellPath String The path to the shell interpreter.
shellScript String The content of the script shell.

Example:

4D22DBAE11674009007AF714 /* ShellScript */ = {
        isa = PBXShellScriptBuildPhase;
        buildActionMask = 2147483647;
        files = (
        );
        inputPaths = (
        );
        outputPaths = (
        );
        runOnlyForDeploymentPostprocessing = 0;
        shellPath = /bin/sh;
        shellScript = "./fix_references.sh";
};

PBXSourcesBuildPhase

This is the element for the sources compilation build phase.

Attribute Type Value Comment
reference UUID A 96 bits identifier
isa PBXSourcesBuildPhase Empty
buildActionMask Number 2^32-1
files List A list of element reference The objects are a reference to a PBXBuildFile element.
runOnlyForDeploymentPostprocessing Number 0

Example:

4DF8B22D1171CFBF0081C1DD /* Sources */ = {
        isa = PBXSourcesBuildPhase;
        buildActionMask = 2147483647;
        files = (
                4DF8B23E1171D0310081C1DD /* test.mm in Sources */,
        );
        runOnlyForDeploymentPostprocessing = 0;
};

PBXTarget

This element is an abstract parent for specialized targets.

PBXTargetDependency

This is the element for referencing other target through content proxies.

Attribute Type Value Comment
reference UUID A 96 bits identifier
isa PBXTargetDependency Empty
target Reference An element reference The object is a reference to a PBXNativeTarget element.
targetProxy Reference An element reference The object is a reference to a PBXContainerItemProxy element.

Example:

4D22DC0D1167C992007AF714 /* PBXTargetDependency */ = {
        isa = PBXTargetDependency;
        target = 87293EBF1153C114007AFD45 /* libXXX */;
        targetProxy = 4D22DC0C1167C992007AF714 /* PBXContainerItemProxy */;
};

PBXVariantGroup

This is the element for referencing localized resources.

Attribute Type Value Comment
reference UUID A 96 bits identifier
isa PBXVariantGroup Empty
children List A list of element reference The objects are a reference to a PBXFileElement element.
name String The filename.
sourceTree String See the PBXSourceTree enumeration.

Example:

870C88031338A77600A69309 /* MainMenu.xib */ = {
        isa = PBXVariantGroup;
        children = (
                870C88041338A77600A69309 /* en */,
        );
        name = MainMenu.xib;
        sourceTree = "";
};

XCBuildConfiguration

This is the element for defining build configuration.

Attribute Type Value Comment
reference UUID A 96 bits identifier
isa XCBuildConfiguration Empty
baseConfigurationReference String The path to a xcconfig file
buildSettings Map A map of build settings.
name String The configuration name.

Example:

870C88151338ABB600A69309 /* Debug */ = {
        isa = XCBuildConfiguration;
        buildSettings = {
                PRODUCT_NAME = "$(TARGET_NAME)";
        };
        name = Debug;
};
870C88161338ABB600A69309 /* Release */ = {
        isa = XCBuildConfiguration;
        buildSettings = {
                PRODUCT_NAME = "$(TARGET_NAME)";
        };
        name = Release;
};

XCConfigurationList

This is the element for listing build configurations.

Attribute Type Value Comment
reference UUID A 96 bits identifier
isa XCConfigurationList Empty
buildConfigurations List A list of element reference The objects are a reference to a XCBuildConfiguration element.
defaultConfigurationIsVisible Number 0
defaultConfigurationName String The default configuration name.

Example:

870C87E41338A77600A69309 /* Build configuration list for PBXProject "CocoaApp" */ = {
        isa = XCConfigurationList;
        buildConfigurations = (
                870C88061338A77600A69309 /* Debug */,
                870C88071338A77600A69309 /* Release */,
        );
        defaultConfigurationIsVisible = 0;
        defaultConfigurationName = Release;
};