Class: Xcodeproj::Project::Object::AbstractObject Abstract
- Inherits:
-
Object
- Object
- Xcodeproj::Project::Object::AbstractObject
- Defined in:
- lib/xcodeproj/project/object.rb,
lib/xcodeproj/project/object_attributes.rb
Overview
This is the base class of all object types that can exist in a Xcode project. As such it provides common behavior, but you can only use instances of subclasses of AbstractObject, because this class does not exist in actual Xcode projects.
Almost all the methods implemented by this class are not expected to be used by Xcodeproj clients.
Subclasses should clearly identify which methods reflect the xcodeproj document model and which methods are offered as convenience. Object lists always represent a relationship to many of the model while simple arrays represent dynamically generated values offered a convenience for clients.
Direct Known Subclasses
AbstractBuildPhase, AbstractTarget, PBXBuildFile, PBXBuildRule, PBXContainerItemProxy, PBXFileReference, PBXFileSystemSynchronizedBuildFileExceptionSet, PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet, PBXFileSystemSynchronizedRootGroup, PBXGroup, PBXProject, PBXReferenceProxy, PBXTargetDependency, XCBuildConfiguration, XCConfigurationList, XCLocalSwiftPackageReference, XCRemoteSwiftPackageReference, XCSwiftPackageProductDependency
AbstractObject collapse
-
#isa ⇒ String
readonly
The object’s class name.
-
#project ⇒ Project
readonly
The project that owns the object.
-
#uuid ⇒ String
readonly
The object universally unique identifier.
AbstractObject collapse
-
.isa ⇒ String
The ISA of the class.
-
#display_name ⇒ String
(also: #to_s)
Returns the value of the name attribute or returns a generic name for the object.
-
#remove_from_project ⇒ void
Removes the object from the project by asking to its referrers to remove the reference to it.
-
#sort(_options = nil) ⇒ Object
Sorts the to many attributes of the object according to the display name.
-
#sort_recursively(options = nil) ⇒ Object
Sorts the object and the objects that it references.
Plist related methods collapse
- #ascii_plist_annotation ⇒ Object
- #nested_object_for_hash(object, method) ⇒ Object
-
#pretty_print ⇒ Hash{String => Hash}
A hash suitable to display the object to the user.
- #to_ascii_plist ⇒ Object
-
#to_hash ⇒ Hash
Returns a cascade representation of the object with UUIDs.
Object methods collapse
Instance Attribute Details
#isa ⇒ String (readonly)
Returns the object’s class name.
45 46 47 |
# File 'lib/xcodeproj/project/object.rb', line 45 def isa @isa end |
#project ⇒ Project (readonly)
Returns the project that owns the object.
91 92 93 |
# File 'lib/xcodeproj/project/object.rb', line 91 def project @project end |
#uuid ⇒ String (readonly)
Returns the object universally unique identifier.
87 88 89 |
# File 'lib/xcodeproj/project/object.rb', line 87 def uuid @uuid end |
Class Method Details
.isa ⇒ String
Returns the ISA of the class.
39 40 41 |
# File 'lib/xcodeproj/project/object.rb', line 39 def self.isa @isa ||= name.split('::').last end |
Instance Method Details
#<=>(other) ⇒ Object
487 488 489 |
# File 'lib/xcodeproj/project/object.rb', line 487 def <=>(other) uuid <=> other.uuid end |
#==(other) ⇒ Object
483 484 485 |
# File 'lib/xcodeproj/project/object.rb', line 483 def ==(other) other.is_a?(AbstractObject) && to_hash == other.to_hash end |
#ascii_plist_annotation ⇒ Object
416 417 418 |
# File 'lib/xcodeproj/project/object.rb', line 416 def ascii_plist_annotation " #{display_name} " end |
#display_name ⇒ String Also known as: to_s
Not all concrete classes implement the name attribute and this method prevents from overriding it in plist.
Returns the value of the name attribute or returns a generic name for the object.
133 134 135 136 137 138 139 140 |
# File 'lib/xcodeproj/project/object.rb', line 133 def display_name declared_name = name if self.respond_to?(:name) if declared_name && !declared_name.empty? declared_name else isa.gsub(/^(PBX|XC)/, '') end end |
#inspect ⇒ Object
491 492 493 494 495 496 |
# File 'lib/xcodeproj/project/object.rb', line 491 def inspect optional = '' optional << " name=`#{name}`" if respond_to?(:name) && name optional << " path=`#{path}`" if respond_to?(:path) && path "<#{isa}#{optional} UUID=`#{uuid}`>" end |
#nested_object_for_hash(object, method) ⇒ Object
407 408 409 410 411 412 413 414 |
# File 'lib/xcodeproj/project/object.rb', line 407 def nested_object_for_hash(object, method) case method when :to_ascii_plist Nanaimo::String.new(object.uuid, object.ascii_plist_annotation) else object.uuid end end |
#pretty_print ⇒ Hash{String => Hash}
Returns A hash suitable to display the object to the user.
468 469 470 471 472 473 474 475 |
# File 'lib/xcodeproj/project/object.rb', line 468 def pretty_print if to_many_attributes.count == 1 children = to_many_attributes.first.get_value(self) { display_name => children.map(&:pretty_print) } else display_name end end |
#remove_from_project ⇒ void
The root object is owned by the project and should not be manipulated with this method.
This method returns an undefined value.
Removes the object from the project by asking to its referrers to remove the reference to it.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/xcodeproj/project/object.rb', line 101 def remove_from_project mark_project_as_dirty! project.objects_by_uuid.delete(uuid) referrers.dup.each do |referrer| referrer.remove_reference(self) end to_one_attributes.each do |attrb| object = attrb.get_value(self) object.remove_referrer(self) if object end to_many_attributes.each do |attrb| list = attrb.get_value(self) list.clear end unless referrers.count == 0 raise "[Xcodeproj] BUG: #{self} should have no referrers instead" \ "the following objects are still referencing it #{referrers}" end end |
#sort(_options = nil) ⇒ Object
Sorts the to many attributes of the object according to the display name.
146 147 148 149 150 151 152 153 |
# File 'lib/xcodeproj/project/object.rb', line 146 def sort( = nil) to_many_attributes.each do |attrb| list = attrb.get_value(self) list.sort! do |x, y| x.display_name.downcase <=> y.display_name.downcase end end end |
#sort_recursively(options = nil) ⇒ Object
Some objects may in turn refer back to objects higher in the object tree, which will lead to stack level deep errors. These objects should not try to perform a recursive sort, also because these objects would get sorted through other paths in the tree anyways.
At the time of writing the only known case is ‘PBXTargetDependency`.
Sorts the object and the objects that it references.
172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/xcodeproj/project/object.rb', line 172 def sort_recursively( = nil) to_one_attributes.each do |attrb| value = attrb.get_value(self) value.sort_recursively() if value end to_many_attributes.each do |attrb| list = attrb.get_value(self) list.each { |entry| entry.sort_recursively() } end sort() end |
#to_ascii_plist ⇒ Object
420 421 422 |
# File 'lib/xcodeproj/project/object.rb', line 420 def to_ascii_plist Nanaimo::Dictionary.new(to_hash_as(:to_ascii_plist), ascii_plist_annotation) end |
#to_hash ⇒ Hash
the key for simple and to_one attributes usually appears only if there is a value. To-many keys always appear with an empty array.
Returns a cascade representation of the object with UUIDs.
375 376 377 |
# File 'lib/xcodeproj/project/object.rb', line 375 def to_hash to_hash_as end |