Git Product home page Git Product logo

xcodeproject's Introduction

XcodeProject

The Ruby API for working with Xcode project files.

Pledgie Badge

Build Status

Installation

gem install xcodeproject

Getting started

A simple example that displays all targets of the project will look like this:

require 'rubygems'
require 'xcodeproject'

proj = XcodeProject::Project.new('path/to/example.xcodeproj')
proj.read.targets.each do |target|
	puts target.name
end

First, you must create an XcodeProject::Project object like this:

proj = XcodeProject::Project.new('path/to/example.xcodeproj')

Or you can find all projects are located in the specified directory:

projs = XcodeProject::Project.find('path/to/dir')

Or by specified directory pattern:

projs = XcodeProject::Project.find('*/**')

After creating the project object, you can read the data from it:

data = proj.read
p data.target('example').config('Release').build_settings

Or rewrite data:

proj.change do |data|
	data.target('example').config('Release').build_settings['GCC_VERSION'] = 'com.apple.compilers.llvmgcc42'
end

Files, groups and directories

Displaying all of top-level groups:

data.main_group.children.each do |child|
	p child.name
end

Displaying files of specified group:

group = data.group('path/from/main_group')
group.files.each do |file|
	p file.name
end

You can get group's (or file's) group path (the path from the main group):

group.group_path

Directories are groups that are explicitly represented in the file system. For them, you can also get a file path:

group.total_path

You can add a group to project by specifying the path from the main group:

data.add_group('path/from/main_group')

Or from the current group:

group.add_group('path/from/current_group')

To add a directory to the project, you must specify the file path:

data.add_dir('group_path/to/parent', '/file_path/to/dir')
group.add_dir('/file_path/to/dir')

Adding files are same:

data.add_file('group_path/to/parent', '/file_path/to/file')
group.add_file('/file_path/to/file')

You can also remove files, groups and directories from the project:

data.remove_file('path/from/main_group')
data.remove_group('path/from/main_group')

group.remove_file('path/from/current_group')
group.remove_group('path/from/current_group')

Targets

Getting the target object is simple:

target = data.target('example')

After adding a file to the project, you can add it to target's build phase:

file = main_group.add_file('/file_path/to/file')
target.add_source(file)

Or remove from target's build phase:

target.remove_source(file)

Building the project

XcodeProject uses Rake and XcodeBuilder for building projects.

You need to create a rakefile, a simple look like this:

require 'rubygems'
require 'xcodeproject'

proj = XcodeProject::Project.new('path/to/example.xcodeproj')
XcodeProject::Tasks::BuildTask.new(proj)

You will now have access to a variety of tasks such as clean and build. A full list of tasks can be viewed by running rake -T:

$ rake -T
rake example:archive            # Creates an archive build of the specified target(s).
rake example:build              # Builds the specified target(s).
rake example:clean              # Cleans the build using the same build settings.
rake example:cleanbuild         # Builds the specified target(s) from a clean slate.

Configuring your tasks:

XcodeProject::Tasks::BuildTask.new(proj) do |t|
	t.target = "libexample"
	t.configuration = "Release"
end

You can find out more about XcodeBuilder here.

License

XcodeProject is provided under the terms of the the MIT license

xcodeproject's People

Contributors

manifest avatar rolyatwilson avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.