Class: Xcodeproj::Project::Object::PBXContainerItemProxy

Inherits:
AbstractObject
  • Object
show all
Defined in:
lib/xcodeproj/project/object/container_item_proxy.rb

Overview

Note:

This class references the other objects by UUID instead of creating proper relationships because the other objects might be part of another project. This implies that the references to other objects should not increase the retain count of the targets.

Apparently a proxy for another object which might belong another project contained in the same workspace of the project document.

This class is referenced by PBXTargetDependency for information about it usage see the specs of that class.

@todo: This class needs some work to support targets across workspaces,

as the container portal might not be initialized leading
xcodeproj to raise because ti can't find the UUID.

Attributes collapse

Attributes inherited from AbstractObject

#isa, #project, #uuid

Attributes collapse

Methods inherited from AbstractObject

#<=>, #==, #display_name, #inspect, isa, #nested_object_for_hash, #pretty_print, #remove_from_project, #sort, #sort_recursively, #to_ascii_plist, #to_hash

Instance Attribute Details

#container_portalString

TODO:

this is an attribute because a it is usually a reference to the root object or to a file reference to another project. The reference to the root object causes a retain cycle that could cause issues (e.g. in to_tree_hash). Usually those objects are retained by at least another object (the Xcodeproj::Project for the root object and a Xcodeproj::Project::Object::PBXGroup for the reference to another project) and so the referenced object should be serialized.

If this assumption is incorrect, there could be loss of information opening and saving an existing project.

TODO:

This is the external reference that ‘contains’ other proxy items.

Returns apparently the UUID of the root object Xcodeproj::Project::Object::PBXProject of the project containing the represented object.

Returns:



41
# File 'lib/xcodeproj/project/object/container_item_proxy.rb', line 41

attribute :container_portal, String

#proxy_typeString

Note:

@see Constants::PROXY_TYPE.values for valid values.

Returns the type of the proxy.

Returns:

  • (String)

    the type of the proxy.



47
# File 'lib/xcodeproj/project/object/container_item_proxy.rb', line 47

attribute :proxy_type, String

#remote_global_id_stringString

Note:

If the object is in another project the UUID would not be present in the Xcodeproj::Project#objects_by_uuid hash. For this reason this is not an ‘has_one` attribute. It is assumes that if the object belongs to the project at least another object should be retaining it. This assumption is reasonable because this is a proxy class.

If this assumption is incorrect, there could be loss of information opening and saving an existing project.

Returns apparently the UUID of the represented object.

Returns:

  • (String)

    apparently the UUID of the represented object.



62
# File 'lib/xcodeproj/project/object/container_item_proxy.rb', line 62

attribute :remote_global_id_string, String

#remote_infoString

Returns apparently the name of the object represented by the proxy.

Returns:

  • (String)

    apparently the name of the object represented by the proxy.



67
# File 'lib/xcodeproj/project/object/container_item_proxy.rb', line 67

attribute :remote_info, String

Instance Method Details

#ascii_plist_annotationObject



110
111
112
# File 'lib/xcodeproj/project/object/container_item_proxy.rb', line 110

def ascii_plist_annotation
  " #{isa} "
end

#container_portal_annotationObject



94
95
96
97
98
99
100
# File 'lib/xcodeproj/project/object/container_item_proxy.rb', line 94

def container_portal_annotation
  if remote?
    " #{File.basename(project.objects_by_uuid[container_portal].real_path)} "
  else
    project.root_object.ascii_plist_annotation
  end
end

#container_portal_objectObject



85
86
87
88
89
90
91
92
# File 'lib/xcodeproj/project/object/container_item_proxy.rb', line 85

def container_portal_object
  if remote?
    container_portal_file_ref = project.objects_by_uuid[container_portal]
    Project.open(container_portal_file_ref.real_path)
  else
    project
  end
end

#proxied_objectAbstractObject

Get the proxied object

Returns:



81
82
83
# File 'lib/xcodeproj/project/object/container_item_proxy.rb', line 81

def proxied_object
  container_portal_object.objects_by_uuid[remote_global_id_string]
end

#remote?Bool

Checks whether the reference points to a remote project.

Returns:

  • (Bool)


73
74
75
# File 'lib/xcodeproj/project/object/container_item_proxy.rb', line 73

def remote?
  project.root_object.uuid != container_portal
end

#to_hash_as(method = :to_hash) ⇒ Object



102
103
104
105
106
107
108
# File 'lib/xcodeproj/project/object/container_item_proxy.rb', line 102

def to_hash_as(method = :to_hash)
  hash = super
  if method == :to_ascii_plist
    hash['containerPortal'] = Nanaimo::String.new(container_portal, container_portal_annotation)
  end
  hash
end