XcodeEditor 1.6.4

XcodeEditor 1.6.4

测试已测试
Lang语言 Obj-CObjective C
许可证 Apache 2
发布上次发布2015年11月

Jasper Blues维护。



  • 作者:
  • Jasper Blues

描述

一个用于操作Xcode项目文件的API。

用法

将源文件添加到项目

XCProject* project = [[XCProject alloc] initWithFilePath:@"MyProject.xcodeproj"];
XCGroup* group = [project groupWithPathFromRoot:@"Main"];
XCClassDefinition* classDefinition = [[XCClassDefinition alloc] initWithName:@"MyNewClass"];
[classDefinition setHeader:@"<some-header-text>"];
[classDefinition setSource:@"<some-impl-text>"];

[group addClass:classDefinition];
[project save];

复制目标

它将作为项目的一部分被添加。

XCTarget* target = [project targetWithName:@"SomeTarget"];
XCTarget* duplicated = [target duplicateWithTargetName:@"DuplicatedTarget" productName:@"NewProduct"];

指定源文件属于目标

XCSourceFile* sourceFile = [project fileWithName:@"MyNewClass.m"];
XCTarget* examples = [project targetWithName:@"Examples"];
[examples addMember:sourceFile];
[project save];

添加Xib文件

这次,我们将使用XCGroup上的便利方法同时指定目标

XCXibDefinition* xibDefinition = [[XCXibDefinition alloc] initWithName:@"MyXibFile" content:@"<xibXml>"];
[group addXib:xibDefinition toTargets:[project targets]];
[project save];

添加框架

XCFrameworkDefinition* frameworkDefinition =
    [[XCFrameworkDefinition alloc] initWithFilePath:@"<framework path>" copyToDestination:NO];
[group addFramework:frameworkDefinition toTargets:[project targets]];
[project save];

将copyToDestination设置为YES,将导致框架首先被复制到项目中的组的目录内,然后从该处链接。

添加图像资源

XCSourceFileDefinition* sourceFileDefinition = [[XCSourceFileDefinition alloc]
    initWithName:@"MyImageFile.png" data:[NSData dataWithContentsOfFile:<your image file name>]
    type:ImageResourcePNG];

[group addSourceFile:sourceFileDefinition];
[project save];

添加资产目录(ImageSet)

XCSourceFileDefinition* sourceFileDefinition = [XCSourceFileDefinition sourceDefinitionWithAssetCatalogName:<path to asset catalog>];

[group addSourceFile:sourceFileDefinition];
[project save];

添加头文件

XCSourceFileDefinition* header = [[XCSourceFileDefinition alloc]
    initWithName:@"SomeHeader.h" text:<your header text> type:SourceCodeHeader];

[group addSourceFile:header];
[project save];

添加子项目

subProjectDefinition = [XCSubProjectDefinition withName:@"mySubproject" projPath=@"/Path/To/Subproject" type:XcodeProject];
[group addSubProject:subProjectDefinition toTargets:[project targets]];

删除子项目

[group removeSubProject:subProjectDefinition];  //TODO: project should be able to remove itself from parent.

配置目标

我们可以向目标添加/更新链接器标志、头文件搜索路径、C-标志等。这里我们将添加头文件搜索路径

XCTarget* target = [_project targetWithName:_projectName];
for (NSString* configName in [target configurations])
{
    XCBuildConfiguration* configuration = [target configurationWithName:configName];
    NSMutableArray* headerPaths = [[NSMutableArray alloc] init];
    [headerPaths addObject:@"$(inherited)"];
    [headerPaths addObject:@"$(SRCROOT)/include"];        
    [configuration addOrReplaceSetting:headerPaths forKey:@"HEADER_SEARCH_PATHS"];
}

...这些设置通过键添加,正如它们在make文件中出现的样子。(Xcode提供了更人性化的描述)。要为给定的构建设置找到键,请查阅编译器文档。常见设置有:

  • HEADER_SEARCH_PATHS
  • OTHER_LD_FLAGS
  • CLANG_CXX_LANGUAGE_STANDARD
  • CODE_SIGN_IDENTITY
  • GCC_C_LANGUAGE_STANDARD
  • INFOPLIST_FILE
  • LIBRARY_SEARCH_PATHS
  • PRODUCT_NAME
  • PROVISIONING_PROFILE

添加库

XCSourceFile * libSourceFile = [project fileWithName:@"libAmazing.a"];

XCTarget* target = [project targetWithName:self.mProject.projectName];
[target addMember:libSourceFile];

for (NSString* configName in [target configurations]) {
    XCProjectBuildConfig* configuration = [target configurationWithName:configName];
    NSMutableArray* headerPaths = [[NSMutableArray alloc] init];
    [headerPaths addObject:@"$(inherited)"];
    [headerPaths addObject:@"$(PROJECT_DIR)/Amazing"];
    [configuration addOrReplaceSetting:headerPaths forKey:@"LIBRARY_SEARCH_PATHS"];
}

文件写入行为

//Creates the reference in the project and writes the contents to disk. If a file already exists at the 
//specified location, its contents will be updated.
[definition setFileOperationStyle:FileOperationStyleOverwrite]; 
//Creates the reference in the project. If a file already exists at the specified location, the contents will 
//not be updated.
[definition setFileOperationStyle:FileOperationStyleAcceptExisting]; 
//Creates the reference in the project, but does not write to disk. The filesystem is expected to be updated 
//through some other means.
[definition setFileOperationStyle:FileOperationStyleReferenceOnly]; 

构建

在XCode中打开项目并选择Product/Build。或者使用CocoaPods进行安装。

功能请求和贡献

非常欢迎。

如果您正在使用API,请给我发一封电子邮件并告诉我您用它做什么。

兼容性

  • Xcode编辑器已在Xcode 4+上进行了测试。它应该也能在更早版本的Xcode上运行。
  • 现在也支持JetBrains的AppCode IDE!
  • 支持既支持ARC模式也支持MRR模式的内存管理。

谁在使用它?

  • Apportable : 使用Xcode、Objective-C和Cocoa API开发Android应用程序
  • Xamarin:移动应用程序的Calabash自动化功能测试。
  • Peckham:一款用于管理Xcode导入的出色插件
  • Level Helper:iOS和Android上开发2D游戏的RAD框架。
  • Text Mate:OSX上缺失的文本编辑器。

作者

贡献者

谢谢!

许可

Apache License,版本2.0,2004年1月,https://apache.ac.cn/licenses/

  • © 2011 - 2012 Jasper Blues和贡献者。