Class: Xcodeproj::Project
- Inherits:
-
Object
- Object
- Xcodeproj::Project
- Includes:
- Object
- Defined in:
- lib/xcodeproj/project.rb,
lib/xcodeproj/project/object.rb,
lib/xcodeproj/project/object_list.rb,
lib/xcodeproj/project/object/group.rb,
lib/xcodeproj/project/case_converter.rb,
lib/xcodeproj/project/project_helper.rb,
lib/xcodeproj/project/uuid_generator.rb,
lib/xcodeproj/project/object/build_file.rb,
lib/xcodeproj/project/object/build_rule.rb,
lib/xcodeproj/project/object_attributes.rb,
lib/xcodeproj/project/object_dictionary.rb,
lib/xcodeproj/project/object/build_phase.rb,
lib/xcodeproj/project/object/root_object.rb,
lib/xcodeproj/project/object/native_target.rb,
lib/xcodeproj/project/object/file_reference.rb,
lib/xcodeproj/project/object/reference_proxy.rb,
lib/xcodeproj/project/object/target_dependency.rb,
lib/xcodeproj/project/object/configuration_list.rb,
lib/xcodeproj/project/object/build_configuration.rb,
lib/xcodeproj/project/object/container_item_proxy.rb,
lib/xcodeproj/project/object/helpers/groupable_helper.rb,
lib/xcodeproj/project/object/helpers/file_references_factory.rb
Overview
This class represents a Xcode project document.
It can be used to manipulate existing documents or even create new ones from scratch.
An Xcode project document is a plist file where the root is a dictionary containing the following keys:
-
archiveVersion: the version of the document.
-
objectVersion: the version of the objects description.
-
classes: a key that apparently is always empty.
-
objects: a dictionary where the UUID of every object is associated to its attributes.
-
rootObject: the UUID identifier of the root object (Object::PBXProject).
Every object is in turn a dictionary that specifies an ‘isa` (the class of the object) and in accordance to it maintains a set attributes. Those attributes might reference one or more other objects by UUID. If the reference is a collection, it is ordered.
The Project API returns instances of Object::AbstractObject which wrap the objects described in the Xcode project document. All the attributes types are preserved from the plist, except for the relationships which are replaced with objects instead of UUIDs.
An object might be referenced by multiple objects, an when no other object is references it, it becomes unreachable (the root object is referenced by the project itself). Xcodeproj takes care of adding and removing those objects from the ‘objects` dictionary so the project is always in a consistent state.
Defined Under Namespace
Modules: Object, ProjectHelper Classes: ObjectDictionary, ObjectList, UUIDGenerator
Creating objects collapse
-
#generated_uuids ⇒ Array<String>
readonly
The list of all the generated UUIDs.
Instance Attribute Summary collapse
-
#archive_version ⇒ String
readonly
The archive version.
-
#classes ⇒ Hash
readonly
An dictionary whose purpose is unknown.
-
#object_version ⇒ String
readonly
The objects version.
-
#objects_by_uuid ⇒ Hash{String => AbstractObject}
readonly
A hash containing all the objects of the project by UUID.
-
#path ⇒ Pathname
readonly
The path of the project.
-
#root_object ⇒ PBXProject
readonly
The root object of the project.
Initialization collapse
-
#initialize_from_file ⇒ Object
Initializes the instance with the project stored in the ‘path` attribute.
-
#initialize_from_scratch ⇒ Object
Initializes the instance from scratch.
Plist serialization collapse
-
#new_from_plist(uuid, objects_by_uuid_plist, root_object = false) ⇒ AbstractObject
Creates a new object from the given UUID and ‘objects` hash (of a plist).
-
#predictabilize_uuids ⇒ void
Replaces all the UUIDs in the project with deterministic MD5 checksums.
-
#pretty_print ⇒ Hash{String => Hash}
A hash suitable to display the project to the user.
-
#save(save_path = nil) ⇒ void
Serializes the project in the xcodeproj format using the path provided during initialization or the given path (‘xcodeproj` file).
-
#to_hash ⇒ Hash
The hash representation of the project.
-
#to_tree_hash ⇒ Hash
Converts the objects tree to a hash substituting the hash of the referenced to their UUID reference.
Creating objects collapse
-
#generate_available_uuid_list(count = 100) ⇒ void
Pre-generates the given number of UUIDs.
-
#generate_uuid ⇒ String
Generates a UUID unique for the project.
-
#new(klass) ⇒ AbstractObject
Creates a new object with a suitable UUID.
Convenience accessors collapse
-
#[](group_path) ⇒ PBXGroup
Returns a group at the given subpath relative to the main group.
-
#build_configuration_list ⇒ ObjectList<XCConfigurationList>
The build configuration list of the project.
-
#build_configurations ⇒ ObjectList<XCBuildConfiguration>
A list of project wide build configurations.
-
#build_settings(name) ⇒ Hash
Returns the build settings of the project wide build configuration with the given name.
-
#files ⇒ ObjectList<PBXFileReference>
A list of all the files in the project.
-
#frameworks_group ⇒ PBXGroup
The ‘Frameworks` group creating it if necessary.
-
#groups ⇒ ObjectList<PBXGroup>
A list of all the groups in the project.
-
#list_by_class(klass) ⇒ Array<AbstractObject>
All the objects of the project with a given ISA.
-
#main_group ⇒ PBXGroup
The main top-level group.
-
#native_targets ⇒ ObjectList<PBXNativeTarget>
A list of all the targets in the project excluding aggregate targets.
-
#objects ⇒ Array<AbstractObject>
All the objects of the project.
-
#products ⇒ ObjectList<PBXFileReference>
A list of the product file references.
-
#products_group ⇒ PBXGroup
The group which holds the product file references.
-
#reference_for_path(absolute_path) ⇒ PBXFileReference, Nil
Returns the file reference for the given absolute path.
-
#targets ⇒ ObjectList<AbstractTarget>
A list of all the targets in the project.
-
#uuids ⇒ Array<String>
All the UUIDs of the project.
Helpers collapse
-
#add_build_configuration(name, type) ⇒ XCBuildConfiguration
Adds a new build configuration to the project and populates its with default settings according to the provided type.
-
#new_aggregate_target(name, target_dependencies = []) ⇒ PBXNativeTarget
Creates a new target and adds it to the project.
-
#new_file(path, source_tree = :group) ⇒ PBXFileReference
Creates a new file reference in the main group.
-
#new_group(name, path = nil, source_tree = :group) ⇒ PBXGroup
Creates a new group at the given subpath of the main group.
-
#new_resources_bundle(name, platform, product_group = nil) ⇒ PBXNativeTarget
Creates a new resource bundles target and adds it to the project.
-
#new_target(type, name, platform, deployment_target = nil, product_group = nil, language = nil) ⇒ PBXNativeTarget
Creates a new target and adds it to the project.
-
#sort(options = nil) ⇒ void
Sorts the project.
Schemes collapse
-
.schemes(project_path) ⇒ Array
Get list of shared schemes in project.
-
#recreate_user_schemes(visible = true) ⇒ void
Recreates the user schemes of the project from scratch (removes the folder) and optionally hides them.
Class Method Summary collapse
-
.open(path) ⇒ Object
Opens the project at the given path.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
A fast way to see if two Project instances refer to the same projects on disk.
-
#eql?(other) ⇒ Boolean
Compares the project to another one, or to a plist representation.
-
#initialize(path, skip_initialization = false, object_version = Constants::DEFAULT_OBJECT_VERSION) ⇒ Project
constructor
A new instance of Project.
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(path, skip_initialization = false, object_version = Constants::DEFAULT_OBJECT_VERSION) ⇒ Project
Returns a new instance of Project.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/xcodeproj/project.rb', line 58 def initialize(path, skip_initialization = false, object_version = Constants::DEFAULT_OBJECT_VERSION) @path = Pathname.new(path). @objects_by_uuid = {} @generated_uuids = [] @available_uuids = [] unless skip_initialization initialize_from_scratch @object_version = object_version.to_s end unless skip_initialization.is_a?(TrueClass) || skip_initialization.is_a?(FalseClass) raise ArgumentError, '[Xcodeproj] Initialization parameter expected to ' \ "be a boolean #{skip_initialization}" end end |
Instance Attribute Details
#archive_version ⇒ String (readonly)
Returns the archive version.
101 102 103 |
# File 'lib/xcodeproj/project.rb', line 101 def archive_version @archive_version end |
#classes ⇒ Hash (readonly)
Returns an dictionary whose purpose is unknown.
105 106 107 |
# File 'lib/xcodeproj/project.rb', line 105 def classes @classes end |
#generated_uuids ⇒ Array<String> (readonly)
Used for checking new UUIDs for duplicates with UUIDs already generated but used for objects which are not yet part of the ‘objects` hash but which might be added at a later time.
Returns the list of all the generated UUIDs.
390 391 392 |
# File 'lib/xcodeproj/project.rb', line 390 def generated_uuids @generated_uuids end |
#object_version ⇒ String (readonly)
Returns the objects version.
109 110 111 |
# File 'lib/xcodeproj/project.rb', line 109 def object_version @object_version end |
#objects_by_uuid ⇒ Hash{String => AbstractObject} (readonly)
Returns A hash containing all the objects of the project by UUID.
114 115 116 |
# File 'lib/xcodeproj/project.rb', line 114 def objects_by_uuid @objects_by_uuid end |
#path ⇒ Pathname (readonly)
Returns the path of the project.
46 47 48 |
# File 'lib/xcodeproj/project.rb', line 46 def path @path end |
#root_object ⇒ PBXProject (readonly)
Returns the root object of the project.
118 119 120 |
# File 'lib/xcodeproj/project.rb', line 118 def root_object @root_object end |
Class Method Details
.open(path) ⇒ Object
Opens the project at the given path.
89 90 91 92 93 94 95 96 97 |
# File 'lib/xcodeproj/project.rb', line 89 def self.open(path) path = Pathname.pwd + path unless Pathname.new(path).exist? raise "[Xcodeproj] Unable to open `#{path}` because it doesn't exist." end project = new(path, true) project.send(:initialize_from_file) project end |
.schemes(project_path) ⇒ Array
Get list of shared schemes in project
705 706 707 708 709 710 711 |
# File 'lib/xcodeproj/project.rb', line 705 def self.schemes(project_path) schemes = Dir[File.join(project_path, 'xcshareddata', 'xcschemes', '*.xcscheme')].map do |scheme| File.basename(scheme, '.xcscheme') end schemes << File.basename(project_path, '.xcodeproj') if schemes.empty? schemes end |
Instance Method Details
#==(other) ⇒ Boolean
If ever needed, we could also compare ‘uuids.sort` instead.
A fast way to see if two Xcodeproj::Project instances refer to the same projects on disk. Use this over #eql? when you do not need to compare the full data.
This shallow comparison was chosen as the (common) ‘==` implementation, because it was too easy to introduce changes into the Xcodeproj code-base that were slower than O(1).
133 134 135 |
# File 'lib/xcodeproj/project.rb', line 133 def ==(other) other && path == other.path && root_object.uuid == other.root_object.uuid end |
#[](group_path) ⇒ PBXGroup
Returns a group at the given subpath relative to the main group.
460 461 462 |
# File 'lib/xcodeproj/project.rb', line 460 def [](group_path) main_group[group_path] end |
#add_build_configuration(name, type) ⇒ XCBuildConfiguration
Adds a new build configuration to the project and populates its with default settings according to the provided type.
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 |
# File 'lib/xcodeproj/project.rb', line 664 def add_build_configuration(name, type) build_configuration_list = root_object.build_configuration_list if build_configuration = build_configuration_list[name] build_configuration else build_configuration = new(XCBuildConfiguration) build_configuration.name = name common_settings = Constants::PROJECT_DEFAULT_BUILD_SETTINGS settings = ProjectHelper.deep_dup(common_settings[:all]) settings.merge!(ProjectHelper.deep_dup(common_settings[type])) build_configuration.build_settings = settings build_configuration_list.build_configurations << build_configuration build_configuration end end |
#build_configuration_list ⇒ ObjectList<XCConfigurationList>
Returns The build configuration list of the project.
527 528 529 |
# File 'lib/xcodeproj/project.rb', line 527 def build_configuration_list root_object.build_configuration_list end |
#build_configurations ⇒ ObjectList<XCBuildConfiguration>
Returns A list of project wide build configurations.
534 535 536 |
# File 'lib/xcodeproj/project.rb', line 534 def build_configurations root_object.build_configuration_list.build_configurations end |
#build_settings(name) ⇒ Hash
Returns the build settings of the project wide build configuration with the given name.
546 547 548 |
# File 'lib/xcodeproj/project.rb', line 546 def build_settings(name) root_object.build_configuration_list.build_settings(name) end |
#eql?(other) ⇒ Boolean
This operation can be extremely expensive, because it converts a ‘Project` instance to a hash, and should only ever be used to determine wether or not the data contents of two `Project` instances are completely equal.
To simply determine wether or not two Xcodeproj::Project instances refer to the same projects on disk, use the #== method instead.
Compares the project to another one, or to a plist representation.
151 152 153 |
# File 'lib/xcodeproj/project.rb', line 151 def eql?(other) other.respond_to?(:to_hash) && to_hash == other.to_hash end |
#files ⇒ ObjectList<PBXFileReference>
Returns a list of all the files in the project.
467 468 469 |
# File 'lib/xcodeproj/project.rb', line 467 def files objects.grep(PBXFileReference) end |
#frameworks_group ⇒ PBXGroup
Returns the ‘Frameworks` group creating it if necessary.
520 521 522 |
# File 'lib/xcodeproj/project.rb', line 520 def frameworks_group main_group['Frameworks'] || main_group.new_group('Frameworks') end |
#generate_available_uuid_list(count = 100) ⇒ void
This method might generated a minor number of uniques UUIDs than the given count, because some might be duplicated a thus will be discarded.
This method returns an undefined value.
Pre-generates the given number of UUIDs. Useful for optimizing performance when the rough number of objects that will be created is known in advance.
405 406 407 408 409 410 |
# File 'lib/xcodeproj/project.rb', line 405 def generate_available_uuid_list(count = 100) new_uuids = (0..count).map { SecureRandom.hex(12).upcase } uniques = (new_uuids - (@generated_uuids + uuids)) @generated_uuids += uniques @available_uuids += uniques end |
#generate_uuid ⇒ String
UUIDs are not guaranteed to be generated unique because we need to trim the ones generated in the xcodeproj extension.
Implementation detail: as objects usually are created serially this method creates a batch of UUID and stores the not colliding ones, so the search for collisions with known UUIDS (a performance bottleneck) is performed less often.
Generates a UUID unique for the project.
379 380 381 382 |
# File 'lib/xcodeproj/project.rb', line 379 def generate_uuid generate_available_uuid_list while @available_uuids.empty? @available_uuids.shift end |
#groups ⇒ ObjectList<PBXGroup>
Returns a list of all the groups in the project.
445 446 447 |
# File 'lib/xcodeproj/project.rb', line 445 def groups main_group.groups end |
#initialize_from_file ⇒ Object
Initializes the instance with the project stored in the ‘path` attribute.
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/xcodeproj/project.rb', line 191 def initialize_from_file pbxproj_path = path + 'project.pbxproj' plist = Xcodeproj.read_plist(pbxproj_path.to_s) root_object.remove_referrer(self) if root_object @root_object = new_from_plist(plist['rootObject'], plist['objects'], self) @archive_version = plist['archiveVersion'] @object_version = plist['objectVersion'] @classes = plist['classes'] unless root_object raise "[Xcodeproj] Unable to find a root object in #{pbxproj_path}." end if archive_version.to_i > Constants::LAST_KNOWN_ARCHIVE_VERSION raise '[Xcodeproj] Unknown archive version.' end if object_version.to_i > Constants::LAST_KNOWN_OBJECT_VERSION raise '[Xcodeproj] Unknown object version.' end end |
#initialize_from_scratch ⇒ Object
Initializes the instance from scratch.
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/xcodeproj/project.rb', line 168 def initialize_from_scratch @archive_version = Constants::LAST_KNOWN_ARCHIVE_VERSION.to_s @classes = {} root_object.remove_referrer(self) if root_object @root_object = new(PBXProject) root_object.add_referrer(self) root_object.main_group = new(PBXGroup) root_object.product_ref_group = root_object.main_group.new_group('Products') config_list = new(XCConfigurationList) root_object.build_configuration_list = config_list config_list.default_configuration_name = 'Release' config_list.default_configuration_is_visible = '0' add_build_configuration('Debug', :debug) add_build_configuration('Release', :release) new_group('Frameworks') end |
#list_by_class(klass) ⇒ Array<AbstractObject>
Returns all the objects of the project with a given ISA.
432 433 434 |
# File 'lib/xcodeproj/project.rb', line 432 def list_by_class(klass) objects.select { |o| o.class == klass } end |
#main_group ⇒ PBXGroup
Returns the main top-level group.
438 439 440 |
# File 'lib/xcodeproj/project.rb', line 438 def main_group root_object.main_group end |
#native_targets ⇒ ObjectList<PBXNativeTarget>
Returns A list of all the targets in the project excluding aggregate targets.
501 502 503 |
# File 'lib/xcodeproj/project.rb', line 501 def native_targets root_object.targets.grep(PBXNativeTarget) end |
#new(klass) ⇒ AbstractObject
Creates a new object with a suitable UUID.
The object is only configured with the default values of the ‘:simple` attributes, for this reason it is better to use the convenience methods offered by the Xcodeproj::Project::Object::AbstractObject subclasses or by this class.
358 359 360 361 362 363 364 365 |
# File 'lib/xcodeproj/project.rb', line 358 def new(klass) if klass.is_a?(String) klass = Object.const_get(klass) end object = klass.new(self, generate_uuid) object.initialize_defaults object end |
#new_aggregate_target(name, target_dependencies = []) ⇒ PBXNativeTarget
Creates a new target and adds it to the project.
The target is configured for the given platform and its file reference it is added to the #products_group.
The target is pre-populated with common build settings, and the appropriate Framework according to the platform is added to to its Frameworks phase.
644 645 646 647 648 649 650 |
# File 'lib/xcodeproj/project.rb', line 644 def new_aggregate_target(name, target_dependencies = []) ProjectHelper.new_aggregate_target(self, name).tap do |aggregate_target| target_dependencies.each do |dep| aggregate_target.add_dependency(dep) end end end |
#new_file(path, source_tree = :group) ⇒ PBXFileReference
Creates a new file reference in the main group.
561 562 563 |
# File 'lib/xcodeproj/project.rb', line 561 def new_file(path, source_tree = :group) main_group.new_file(path, source_tree) end |
#new_from_plist(uuid, objects_by_uuid_plist, root_object = false) ⇒ AbstractObject
This method is used to generate the root object from a plist. Subsequent invocation are called by the Xcodeproj::Project::Object::AbstractObject#configure_with_plist. Clients of Xcodeproj are not expected to call this method.
Creates a new object from the given UUID and ‘objects` hash (of a plist).
The method sets up any relationship of the new object, generating the destination object(s) if not already present in the project.
243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/xcodeproj/project.rb', line 243 def new_from_plist(uuid, objects_by_uuid_plist, root_object = false) attributes = objects_by_uuid_plist[uuid] if attributes klass = Object.const_get(attributes['isa']) object = klass.new(self, uuid) objects_by_uuid[uuid] = object object.add_referrer(self) if root_object object.configure_with_plist(objects_by_uuid_plist) object end end |
#new_group(name, path = nil, source_tree = :group) ⇒ PBXGroup
Creates a new group at the given subpath of the main group.
571 572 573 |
# File 'lib/xcodeproj/project.rb', line 571 def new_group(name, path = nil, source_tree = :group) main_group.new_group(name, path, source_tree) end |
#new_resources_bundle(name, platform, product_group = nil) ⇒ PBXNativeTarget
Creates a new resource bundles target and adds it to the project.
The target is configured for the given platform and its file reference it is added to the #products_group.
The target is pre-populated with common build settings
622 623 624 625 |
# File 'lib/xcodeproj/project.rb', line 622 def new_resources_bundle(name, platform, product_group = nil) product_group ||= products_group ProjectHelper.new_resources_bundle(self, name, platform, product_group) end |
#new_target(type, name, platform, deployment_target = nil, product_group = nil, language = nil) ⇒ PBXNativeTarget
Creates a new target and adds it to the project.
The target is configured for the given platform and its file reference it is added to the #products_group.
The target is pre-populated with common build settings, and the appropriate Framework according to the platform is added to to its Frameworks phase.
602 603 604 605 |
# File 'lib/xcodeproj/project.rb', line 602 def new_target(type, name, platform, deployment_target = nil, product_group = nil, language = nil) product_group ||= products_group ProjectHelper.new_target(self, type, name, platform, deployment_target, product_group, language) end |
#objects ⇒ Array<AbstractObject>
Returns all the objects of the project.
419 420 421 |
# File 'lib/xcodeproj/project.rb', line 419 def objects objects_by_uuid.values end |
#predictabilize_uuids ⇒ void
The current sorting of the project is taken into account when generating the new UUIDs.
This method should only be used for entirely machine-generated projects, as true UUIDs are useful for tracking changes in the project.
This method returns an undefined value.
Replaces all the UUIDs in the project with deterministic MD5 checksums.
337 338 339 |
# File 'lib/xcodeproj/project.rb', line 337 def predictabilize_uuids UUIDGenerator.new(self).generate! end |
#pretty_print ⇒ Hash{String => Hash}
Returns A hash suitable to display the project to the user.
295 296 297 298 299 300 301 302 |
# File 'lib/xcodeproj/project.rb', line 295 def pretty_print build_configurations = root_object.build_configuration_list.build_configurations { 'File References' => root_object.main_group.pretty_print.values.first, 'Targets' => root_object.targets.map(&:pretty_print), 'Build Configurations' => build_configurations.sort_by(&:name).map(&:pretty_print), } end |
#products ⇒ ObjectList<PBXFileReference>
Returns A list of the product file references.
514 515 516 |
# File 'lib/xcodeproj/project.rb', line 514 def products products_group.children end |
#products_group ⇒ PBXGroup
Returns The group which holds the product file references.
507 508 509 |
# File 'lib/xcodeproj/project.rb', line 507 def products_group root_object.product_ref_group end |
#recreate_user_schemes(visible = true) ⇒ void
This method returns an undefined value.
Recreates the user schemes of the project from scratch (removes the folder) and optionally hides them.
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 |
# File 'lib/xcodeproj/project.rb', line 721 def recreate_user_schemes(visible = true) schemes_dir = XCScheme.user_data_dir(path) FileUtils.rm_rf(schemes_dir) FileUtils.mkdir_p(schemes_dir) xcschememanagement = {} xcschememanagement['SchemeUserState'] = {} xcschememanagement['SuppressBuildableAutocreation'] = {} targets.each do |target| scheme = XCScheme.new scheme.add_build_target(target) scheme.save_as(path, target.name, false) xcschememanagement['SchemeUserState']["#{target.name}.xcscheme"] = {} xcschememanagement['SchemeUserState']["#{target.name}.xcscheme"]['isShown'] = visible end xcschememanagement_path = schemes_dir + 'xcschememanagement.plist' Xcodeproj.write_plist(xcschememanagement, xcschememanagement_path) end |
#reference_for_path(absolute_path) ⇒ PBXFileReference, Nil
Returns the file reference for the given absolute path.
479 480 481 482 483 484 485 486 487 488 489 |
# File 'lib/xcodeproj/project.rb', line 479 def reference_for_path(absolute_path) absolute_pathname = Pathname.new(absolute_path) unless absolute_pathname.absolute? raise ArgumentError, "Paths must be absolute #{absolute_path}" end objects.find do |child| child.isa == 'PBXFileReference' && child.real_path == absolute_pathname end end |
#save(save_path = nil) ⇒ void
This method returns an undefined value.
Serializes the project in the xcodeproj format using the path provided during initialization or the given path (‘xcodeproj` file). If a path is provided file references depending on the root of the project are not updated automatically, thus clients are responsible to perform any needed modification before saving.
319 320 321 322 323 324 |
# File 'lib/xcodeproj/project.rb', line 319 def save(save_path = nil) save_path ||= path FileUtils.mkdir_p(save_path) file = File.join(save_path, 'project.pbxproj') Xcodeproj.write_plist(to_hash, file) end |
#sort(options = nil) ⇒ void
This method returns an undefined value.
Sorts the project.
689 690 691 |
# File 'lib/xcodeproj/project.rb', line 689 def sort( = nil) root_object.sort_recursively() end |
#targets ⇒ ObjectList<AbstractTarget>
Returns A list of all the targets in the project.
494 495 496 |
# File 'lib/xcodeproj/project.rb', line 494 def targets root_object.targets end |
#to_hash ⇒ Hash
Returns The hash representation of the project.
257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/xcodeproj/project.rb', line 257 def to_hash plist = {} objects_dictionary = {} objects.each { |obj| objects_dictionary[obj.uuid] = obj.to_hash } plist['objects'] = objects_dictionary plist['archiveVersion'] = archive_version.to_s plist['objectVersion'] = object_version.to_s plist['classes'] = classes plist['rootObject'] = root_object.uuid plist end |
#to_s ⇒ Object Also known as: inspect
155 156 157 |
# File 'lib/xcodeproj/project.rb', line 155 def to_s "#<#{self.class}> path:`#{path}` UUID:`#{root_object.uuid}`" end |
#to_tree_hash ⇒ Hash
Converts the objects tree to a hash substituting the hash of the referenced to their UUID reference. As a consequence the hash of an object might appear multiple times and the information about their uniqueness is lost.
This method is designed to work in conjunction with Hash#recursive_diff to provide a complete, yet readable, diff of two projects not affected by differences in UUIDs.
281 282 283 284 285 286 287 288 289 290 |
# File 'lib/xcodeproj/project.rb', line 281 def to_tree_hash hash = {} objects_dictionary = {} hash['objects'] = objects_dictionary hash['archiveVersion'] = archive_version.to_s hash['objectVersion'] = object_version.to_s hash['classes'] = classes hash['rootObject'] = root_object.to_tree_hash hash end |
#uuids ⇒ Array<String>
Returns all the UUIDs of the project.
425 426 427 |
# File 'lib/xcodeproj/project.rb', line 425 def uuids objects_by_uuid.keys end |