class Xcodeproj::Project
described in the Xcode project document.
The Project API returns instances of AbstractPBXObject which wrap the objects
from scratch.
It can be used to manipulate existing documents or even create new ones
This class represents a Xcode project document.
def ==(other)
def ==(other) other.respond_to?(:to_hash) && @plist == other.to_hash end
def add_object_hash(uuid, attributes)
- Todo: - Ideally we would do more validation here, but I don't think we know
Raises:
-
(ArgumentError)- Raised if the value of the `isa` key is equal
Parameters:
-
attributes(Hash) -- The attributes of the object. -
uuid(String) -- The UUID of the object.
def add_object_hash(uuid, attributes) if attributes['isa'] !~ /^(PBX|XC)/ raise ArgumentError, "Attempted to insert a `#{attributes['isa']}' instance into the objects hash, which is not allowed." end objects_hash[uuid] = attributes end
def add_system_framework(name)
-
(PBXFileReference)- The file reference object.
Parameters:
-
name(String) -- The name of a framework in the SDK System
Other tags:
- Todo: - Make it possible to do: `build_phase << framework`
def add_system_framework(name) path = "System/Library/Frameworks/#{name}.framework" if file = files.where(:path => path) file else group = groups.where('name' => 'Frameworks') || groups.new('name' => 'Frameworks') group.files.new({ 'name' => "#{name}.framework", 'path' => path, 'sourceTree' => 'SDKROOT' }) end end
def build_configurations
-
(PBXObjectList- PBXObjectList
def build_configurations root_object.build_configuration_list.build_configurations end
def build_settings(name)
-
(Hash)- The build settings of the project wide build
Parameters:
-
name(String) -- The name of a project wide build configuration.
def build_settings(name) root_object.build_configuration_list.build_settings(name) end
def files
-
(PBXObjectList- A list of all the files in the)
def files objects.list_by_class(PBXFileReference) end
def group(name)
-
(PBXGroup, nil)- The PBXgroup, if found.
Parameters:
-
name(String) -- The name of the group to find.
def group(name) groups.object_named(name) end
def groups
-
(PBXObjectList- A list of all the groups in the)
def groups objects.list_by_class(PBXGroup) end
def initialize(xcodeproj = nil)
-
(Project)- A new Project instance or one with
Parameters:
-
xcodeproj(Pathname, String) -- The path to the Xcode project
def initialize(xcodeproj = nil) if xcodeproj file = File.join(xcodeproj, 'project.pbxproj') @plist = Xcodeproj.read_plist(file.to_s) else @plist = { 'archiveVersion' => '1', 'classes' => {}, 'objectVersion' => '46', 'objects' => {} } main_group = groups.new self.root_object = objects.add(PBXProject, { 'attributes' => { 'LastUpgradeCheck' => '0420' }, 'compatibilityVersion' => 'Xcode 3.2', 'developmentRegion' => 'English', 'hasScannedForEncodings' => '0', 'knownRegions' => ['en'], 'mainGroup' => main_group.uuid, 'productRefGroup' => main_group.groups.new('name' => 'Products').uuid, 'projectDirPath' => '', 'projectRoot' => '', 'targets' => [] }) config_list = objects.add(XCConfigurationList) config_list.default_configuration_name = 'Release' config_list.default_configuration_is_visible = '0' config_list.build_configurations.new('name' => 'Debug') config_list.build_configurations.new('name' => 'Release') self.root_object.build_configuration_list = config_list # TODO make this work #self.root_object.product_reference = groups.new('name' => 'Products').uuid end end
def main_group
-
(PBXGroup)- The main top-level group.
def main_group objects[root_object.attributes['mainGroup']] end
def objects
-
(PBXObjectList- A list of all the objects in the)
def objects PBXObjectList.new(AbstractPBXObject, self) do |list| list.let(:uuid_scope) { objects_hash.keys } end end
def objects_hash
-
(Hash)- The `objects` part of the internal data.
def objects_hash @plist['objects'] end
def products
-
(PBXObjectList- A list of the product file)
def products products_group.children end
def products_group
-
(PBXGroup)- The group which holds the product file references.
def products_group root_object.products_group end
def root_object
-
(PBXProject)- The root object of the project.
def root_object objects[@plist['rootObject']] end
def root_object=(object)
-
object(PBXProject) -- The object to assign as the root object.
def root_object=(object) @plist['rootObject'] = object.uuid end
def save_as(projpath)
-
(true, false)- Returns whether or not saving was
Parameters:
-
projpath(String, Pathname) -- The path where the data should be
def save_as(projpath) projpath = projpath.to_s FileUtils.mkdir_p(projpath) Xcodeproj.write_plist(@plist, File.join(projpath, 'project.pbxproj')) end
def source_files
-
(Hash)- A list of all the groups and their source files.
Other tags:
- Todo: - I think this is here because of easier testing in CocoaPods. Move
def source_files source_files = {} groups.each do |group| next if group.name.nil? || IGNORE_GROUPS.include?(group.name) source_files[group.name] = group.source_files.map(&:pathname) end source_files end
def targets
-
(PBXObjectList- A list of all the targets in)
Other tags:
- Todo: - There are probably other target types too. E.g. an aggregate.
def targets # Better to check the project object for targets to ensure they are # actually there so the project will work root_object.targets end
def to_hash
-
(Hash)- The internal data.
def to_hash @plist end