Class: Xcodeproj::Project

Inherits:
Object
  • Object
show all
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/xcproj_helper.rb,
lib/xcodeproj/project/project_helper.rb,
lib/xcodeproj/project/case_converter.rb,
lib/xcodeproj/project/object/build_rule.rb,
lib/xcodeproj/project/object_attributes.rb,
lib/xcodeproj/project/object/build_file.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, XCProjHelper Classes: ObjectDictionary, ObjectList

Creating objects collapse

Instance Attribute Summary collapse

Initialization collapse

Plist serialization collapse

Creating objects collapse

Convenience accessors collapse

Helpers collapse

Schemes collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, skip_initialization = false) ⇒ Project

Returns a new instance of Project.

Examples:

Creating a project

Project.new("path/to/Project.xcodeproj")

Parameters:

  • path (Pathname, String)

    @see path The path provided will be expanded to an absolute path.

  • skip_initialization (Bool) (defaults to: false)

    Wether the project should be initialized from scratch.


57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/xcodeproj/project.rb', line 57

def initialize(path, skip_initialization = false)
  @path = Pathname.new(path).expand_path
  @objects_by_uuid = {}
  @generated_uuids = []
  @available_uuids = []
  unless skip_initialization
    initialize_from_scratch
  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_versionString (readonly)

Returns the archive version.

Returns:

  • (String)

    the archive version.


99
100
101
# File 'lib/xcodeproj/project.rb', line 99

def archive_version
  @archive_version
end

#classesHash (readonly)

Returns an dictionary whose purpose is unknown.

Returns:

  • (Hash)

    an dictionary whose purpose is unknown.


103
104
105
# File 'lib/xcodeproj/project.rb', line 103

def classes
  @classes
end

#disable_xcprojBoolean

Returns Whether the xcproj conversion should be disabled. The conversion can also be disabled via the XCODEPROJ_DISABLE_XCPROJ environment variable.

Returns:

  • (Boolean)

    Whether the xcproj conversion should be disabled. The conversion can also be disabled via the XCODEPROJ_DISABLE_XCPROJ environment variable.


163
164
165
# File 'lib/xcodeproj/project.rb', line 163

def disable_xcproj
  @disable_xcproj
end

#generated_uuidsArray<String> (readonly)

Note:

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.

Returns:

  • (Array<String>)

    the list of all the generated UUIDs.


415
416
417
# File 'lib/xcodeproj/project.rb', line 415

def generated_uuids
  @generated_uuids
end

#object_versionString (readonly)

Returns the objects version.

Returns:

  • (String)

    the objects version.


107
108
109
# File 'lib/xcodeproj/project.rb', line 107

def object_version
  @object_version
end

#objects_by_uuidHash{String => AbstractObject} (readonly)

Returns A hash containing all the objects of the project by UUID.

Returns:

  • (Hash{String => AbstractObject})

    A hash containing all the objects of the project by UUID.


112
113
114
# File 'lib/xcodeproj/project.rb', line 112

def objects_by_uuid
  @objects_by_uuid
end

#pathPathname (readonly)

Returns the path of the project.

Returns:

  • (Pathname)

    the path of the project.


47
48
49
# File 'lib/xcodeproj/project.rb', line 47

def path
  @path
end

#root_objectPBXProject (readonly)

Returns the root object of the project.

Returns:

  • (PBXProject)

    the root object of the project.


116
117
118
# File 'lib/xcodeproj/project.rb', line 116

def root_object
  @root_object
end

Class Method Details

.open(path) ⇒ Object

Opens the project at the given path.

Examples:

Opening a project

Project.open("path/to/Project.xcodeproj")

Parameters:

  • path (Pathname, String)

    The path to the Xcode project document (xcodeproj).

Raises:

  • If the project versions are more recent than the ones know to Xcodeproj to prevent it from corrupting existing projects. Naturally, this would never happen with a project generated by xcodeproj itself.

  • If it can't find the root object. This means that the project is malformed.


87
88
89
90
91
92
93
94
95
# File 'lib/xcodeproj/project.rb', line 87

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

Parameters:

  • path (String)

    project path

Returns:

  • (Array)

695
696
697
698
699
700
701
# File 'lib/xcodeproj/project.rb', line 695

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

TODO:

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).

Returns:

  • (Boolean)

    whether or not the two Project instances refer to the same projects on disk, determined solely by #path and root_object.uuid equality.


131
132
133
# File 'lib/xcodeproj/project.rb', line 131

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.

Examples:

frameworks = project['Frameworks']
frameworks.name #=> 'Frameworks'
main_group.children.include? frameworks #=> True

Parameters:

  • group_path (String)

    @see MobileCoreServices

Returns:

  • (PBXGroup)

    the group at the given subpath.


485
486
487
# File 'lib/xcodeproj/project.rb', line 485

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.

Parameters:

  • name (String)

    The name of the build configuration.

  • type (Symbol)

    The type of the build configuration used to populate the build settings, must be :debug or :release.

Returns:


654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
# File 'lib/xcodeproj/project.rb', line 654

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_listObjectList<XCConfigurationList>

Returns The build configuration list of the project.

Returns:


545
546
547
# File 'lib/xcodeproj/project.rb', line 545

def build_configuration_list
  root_object.build_configuration_list
end

#build_configurationsObjectList<XCBuildConfiguration>

Returns A list of project wide build configurations.

Returns:


552
553
554
# File 'lib/xcodeproj/project.rb', line 552

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.

Parameters:

  • name (String)

    The name of a project wide build configuration.

Returns:

  • (Hash)

    The build settings.


564
565
566
# File 'lib/xcodeproj/project.rb', line 564

def build_settings(name)
  root_object.build_configuration_list.build_settings(name)
end

#disable_xcproj?Boolean

Returns:

  • (Boolean)

164
165
166
# File 'lib/xcodeproj/project.rb', line 164

def disable_xcproj?
  @disable_xcproj || ENV['XCODEPROJ_DISABLE_XCPROJ']
end

#eql?(other) ⇒ Boolean

Note:

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.

Parameters:

  • other (#to_hash)

    the object to compare.

Returns:

  • (Boolean)

    whether the project is equivalent to the given object.


149
150
151
# File 'lib/xcodeproj/project.rb', line 149

def eql?(other)
  other.respond_to?(:to_hash) && to_hash == other.to_hash
end

#filesObjectList<PBXFileReference>

Returns a list of all the files in the project.

Returns:


492
493
494
# File 'lib/xcodeproj/project.rb', line 492

def files
  objects.select { |obj| obj.class == PBXFileReference }
end

#fix_encoding(filename) ⇒ void

Note:

This is necessary because Xcode (4.6 currently) uses the MacRoman encoding unless the // !$*UTF8*$! magic comment is present. It is not possible to serialize a plist using the NeXTSTEP format without access to the private classes of Xcode and that comment is not compatible with the XML format. For the complete discussion see CocoaPods/CocoaPods#926.

Note:

Sadly this hack is not sufficient for supporting Emoji.

This method returns an undefined value.

Simple workaround to escape characters which are outside of ASCII character-encoding. Relies on the fact that there are no XML characters which would need to be escaped.

Parameters:

  • The (String, Pathname)

    path of the file which needs to be fixed.


353
354
355
356
357
358
359
360
361
362
363
364
# File 'lib/xcodeproj/project.rb', line 353

def fix_encoding(filename)
  output = ''
  input = File.open(filename, 'rb') { |file| file.read }
  input.unpack('U*').each do |codepoint|
    if codepoint > 127
      output << "&##{codepoint};"
    else
      output << codepoint.chr
    end
  end
  File.open(filename, 'wb') { |file| file.write(output) }
end

#frameworks_groupPBXGroup

Returns the Frameworks group creating it if necessary.

Returns:

  • (PBXGroup)

    the Frameworks group creating it if necessary.


538
539
540
# File 'lib/xcodeproj/project.rb', line 538

def frameworks_group
  main_group['Frameworks'] || main_group.new_group('Frameworks')
end

#generate_available_uuid_list(count = 100) ⇒ void

Note:

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.

Parameters:

  • count (Integer) (defaults to: 100)

    the number of UUIDs that should be generated.


430
431
432
433
434
435
# File 'lib/xcodeproj/project.rb', line 430

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_uuidString

Note:

UUIDs are not guaranteed to be generated unique because we need to trim the ones generated in the xcodeproj extension.

Note:

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.

Returns:

  • (String)

    A UUID unique to the project.


404
405
406
407
# File 'lib/xcodeproj/project.rb', line 404

def generate_uuid
  generate_available_uuid_list while @available_uuids.empty?
  @available_uuids.shift
end

#groupsObjectList<PBXGroup>

Returns a list of all the groups in the project.

Returns:


470
471
472
# File 'lib/xcodeproj/project.rb', line 470

def groups
  main_group.groups
end

#initialize_from_fileObject

Initializes the instance with the project stored in the path attribute.


199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/xcodeproj/project.rb', line 199

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_scratchObject

Initializes the instance from scratch.


175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/xcodeproj/project.rb', line 175

def initialize_from_scratch
  @archive_version =  Constants::LAST_KNOWN_ARCHIVE_VERSION.to_s
  @object_version  =  Constants::LAST_KNOWN_OBJECT_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.

Returns:

  • (Array<AbstractObject>)

    all the objects of the project with a given ISA.


457
458
459
# File 'lib/xcodeproj/project.rb', line 457

def list_by_class(klass)
  objects.select { |o| o.class == klass }
end

#main_groupPBXGroup

Returns the main top-level group.

Returns:

  • (PBXGroup)

    the main top-level group.


463
464
465
# File 'lib/xcodeproj/project.rb', line 463

def main_group
  root_object.main_group
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.

Parameters:

  • klass (Class, String)

    The concrete subclass of AbstractObject for new object or its ISA.

Returns:


383
384
385
386
387
388
389
390
# File 'lib/xcodeproj/project.rb', line 383

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_file(path, source_tree = :group) ⇒ PBXFileReference

Creates a new file reference in the main group.

Parameters:

  • @see

    PBXGroup#new_file

Returns:


579
580
581
# File 'lib/xcodeproj/project.rb', line 579

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

Note:

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.

Parameters:

  • uuid (String)

    The UUID of the object that needs to be generated.

  • objects_by_uuid_plist (Hash {String => Hash})

    The objects hash of the plist representation of the project.

  • root_object (Boolean) (defaults to: false)

    Whether the requested object is the root object and needs to be retained by the project before configuration to add it to the objects hash and avoid infinite loops.

Returns:


251
252
253
254
255
256
257
258
259
260
# File 'lib/xcodeproj/project.rb', line 251

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)
    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.

Parameters:

  • @see

    PBXGroup#new_group

Returns:


589
590
591
# File 'lib/xcodeproj/project.rb', line 589

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

Parameters:

  • name (String)

    the name of the resources bundle.

  • platform (Symbol)

    the platform of the resources bundle. Can be :ios or :osx.

Returns:


637
638
639
640
# File 'lib/xcodeproj/project.rb', line 637

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) ⇒ 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.

Parameters:

  • type (Symbol)

    the type of target. Can be :application, :framework, :dynamic_library or :static_library.

  • name (String)

    the name of the target product.

  • platform (Symbol)

    the platform of the target. Can be :ios or :osx.

  • deployment_target (String) (defaults to: nil)

    the deployment target for the platform.

Returns:


617
618
619
620
# File 'lib/xcodeproj/project.rb', line 617

def new_target(type, name, platform, deployment_target = nil, product_group = nil)
  product_group ||= products_group
  ProjectHelper.new_target(self, type, name, platform, deployment_target, product_group)
end

#objectsArray<AbstractObject>

Returns all the objects of the project.

Returns:


444
445
446
# File 'lib/xcodeproj/project.rb', line 444

def objects
  objects_by_uuid.values
end

#pretty_printHash{String => Hash}

Returns A hash suitable to display the project to the user.

Returns:

  • (Hash{String => Hash})

    A hash suitable to display the project to the user.


302
303
304
305
306
307
308
309
# File 'lib/xcodeproj/project.rb', line 302

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

#productsObjectList<PBXFileReference>

Returns A list of the product file references.

Returns:


532
533
534
# File 'lib/xcodeproj/project.rb', line 532

def products
  products_group.children
end

#products_groupPBXGroup

Returns The group which holds the product file references.

Returns:

  • (PBXGroup)

    The group which holds the product file references.


525
526
527
# File 'lib/xcodeproj/project.rb', line 525

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.

Parameters:

  • visible (Bool) (defaults to: true)

    Wether the schemes should be visible or hidden.


711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
# File 'lib/xcodeproj/project.rb', line 711

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.

Parameters:

  • absolute_path (#to_s)

    The absolute path of the file whose reference is needed.

Returns:

  • (PBXFileReference)

    The file reference.

  • (Nil)

    If no file reference could be found.


504
505
506
507
508
509
510
511
512
513
514
# File 'lib/xcodeproj/project.rb', line 504

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.

Examples:

Saving a project

project.save
project.save

Parameters:

  • path (String, Pathname)

    The optional path where the project should be saved.


326
327
328
329
330
331
332
333
# File 'lib/xcodeproj/project.rb', line 326

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)
  fix_encoding(file)
  XCProjHelper.touch(save_path) unless disable_xcproj?
end

#sort(options = nil) ⇒ void

This method returns an undefined value.

Sorts the project.

Parameters:

  • options (Hash) (defaults to: nil)

    the sorting options.

Options Hash (options):

  • :groups_position (Symbol)

    the position of the groups can be either :above or :below.


679
680
681
# File 'lib/xcodeproj/project.rb', line 679

def sort(options = nil)
  root_object.sort_recursively(options)
end

#targetsObjectList<PBXNativeTarget>

Returns A list of all the targets in the project.

Returns:


519
520
521
# File 'lib/xcodeproj/project.rb', line 519

def targets
  root_object.targets
end

#to_hashHash

Returns The hash representation of the project.

Returns:

  • (Hash)

    The hash representation of the project.


264
265
266
267
268
269
270
271
272
273
274
# File 'lib/xcodeproj/project.rb', line 264

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_sObject Also known as: inspect


153
154
155
# File 'lib/xcodeproj/project.rb', line 153

def to_s
  "#<#{self.class}> path:`#{path}` UUID:`#{root_object.uuid}`"
end

#to_tree_hashHash

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.

Returns:

  • (Hash)

    a hash representation of the project different from the plist one.


288
289
290
291
292
293
294
295
296
297
# File 'lib/xcodeproj/project.rb', line 288

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

#uuidsArray<String>

Returns all the UUIDs of the project.

Returns:

  • (Array<String>)

    all the UUIDs of the project.


450
451
452
# File 'lib/xcodeproj/project.rb', line 450

def uuids
  objects_by_uuid.keys
end