Class: Xcodeproj::Project::Object::PBXFileReference

Inherits:
AbstractObject show all
Defined in:
lib/xcodeproj/project/object/file_reference.rb

Overview

This class represents a reference to a file in the file system.

Attributes collapse

Attributes inherited from AbstractObject

#isa, #project, #uuid

Helpers collapse

Methods inherited from AbstractObject

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

Instance Attribute Details

#commentsString

Note:

This is apparently no longer used by Xcode.

Returns Comments associated with this file.

Returns:

  • (String)

    Comments associated with this file.



122
# File 'lib/xcodeproj/project/object/file_reference.rb', line 122

attribute :comments, String

#expected_signatureString

Returns a string that specifies the signature of an external framework.

Examples:

`AppleDeveloperProgram:TEAM0ID1:Team name`

Returns:

  • (String)

    a string that specifies the signature of an external framework.



116
# File 'lib/xcodeproj/project/object/file_reference.rb', line 116

attribute :expected_signature, String

#explicit_file_typeString

Returns the file type (apparently) used for products generated by Xcode (i.e. applications, libraries).

Returns:

  • (String)

    the file type (apparently) used for products generated by Xcode (i.e. applications, libraries).



36
# File 'lib/xcodeproj/project/object/file_reference.rb', line 36

attribute :explicit_file_type, String

#fileEncodingString

Returns a string containing a number which represents the encoding format of the file.

Returns:

  • (String)

    a string containing a number which represents the encoding format of the file.



56
# File 'lib/xcodeproj/project/object/file_reference.rb', line 56

attribute :fileEncoding, String

#include_in_indexString

Note:

Apparently present only for products generated by Xcode with a value of ‘0`.

Returns whether this file should be indexed. It can be either ‘0` or `1`.

Returns:

  • (String)

    whether this file should be indexed. It can be either ‘0` or `1`.



51
# File 'lib/xcodeproj/project/object/file_reference.rb', line 51

attribute :include_in_index, String, '1'

#indent_widthString

Returns The width of the indent.

Examples:

`2`

Returns:

  • (String)

    The width of the indent.



86
# File 'lib/xcodeproj/project/object/file_reference.rb', line 86

attribute :indent_width, String

#last_known_file_typeString

Note:

This attribute is not present if there is an ‘explicit_file_type`.

Returns the file type guessed by Xcode.

Returns:

  • (String)

    the file type guessed by Xcode.



43
# File 'lib/xcodeproj/project/object/file_reference.rb', line 43

attribute :last_known_file_type, String

#line_endingString

Returns Apparently whether Xcode should add, if needed, a new line feed before saving the file.

Examples:

`0`

Returns:

  • (String)

    Apparently whether Xcode should add, if needed, a new line feed before saving the file.



108
# File 'lib/xcodeproj/project/object/file_reference.rb', line 108

attribute :line_ending, String

#nameString

Returns the name of the reference, often not present.

Returns:

  • (String)

    the name of the reference, often not present.



13
# File 'lib/xcodeproj/project/object/file_reference.rb', line 13

attribute :name, String

#pathString

Returns the path to the file relative to the source tree.

Returns:

  • (String)

    the path to the file relative to the source tree



17
# File 'lib/xcodeproj/project/object/file_reference.rb', line 17

attribute :path, String

#plist_structure_definition_identifierString

Returns a string that specifies the UTI for the structure of a plist file.

Examples:

`com.apple.xcode.plist.structure-definition.iphone.info-plist`

Returns:

  • (String)

    a string that specifies the UTI for the structure of a plist file.



72
# File 'lib/xcodeproj/project/object/file_reference.rb', line 72

attribute :plist_structure_definition_identifier, String

#source_treeString

Note:

The accepted values are:

  • ‘<absolute>` for absolute paths

  • ‘<group>` for paths relative to the group

  • ‘SOURCE_ROOT` for paths relative to the project

  • ‘DEVELOPER_DIR` for paths relative to the developer directory.

  • ‘BUILT_PRODUCTS_DIR` for paths relative to the build products directory.

  • ‘SDKROOT` for paths relative to the SDK directory.

Returns the directory to which the path is relative.

Returns:

  • (String)

    the directory to which the path is relative.



31
# File 'lib/xcodeproj/project/object/file_reference.rb', line 31

attribute :source_tree, String, 'SOURCE_ROOT'

#tab_widthString

Returns The width of the tabs.

Examples:

`2`

Returns:

  • (String)

    The width of the tabs.



93
# File 'lib/xcodeproj/project/object/file_reference.rb', line 93

attribute :tab_width, String

#uses_tabsString

Returns Whether Xcode should use tabs for text alignment.

Examples:

`1`

Returns:

  • (String)

    Whether Xcode should use tabs for text alignment.



79
# File 'lib/xcodeproj/project/object/file_reference.rb', line 79

attribute :uses_tabs, String

#wraps_linesString

Returns Whether Xcode should wrap lines.

Examples:

`1`

Returns:

  • (String)

    Whether Xcode should wrap lines.



100
# File 'lib/xcodeproj/project/object/file_reference.rb', line 100

attribute :wraps_lines, String

#xc_language_specification_identifierString

Returns a string that specifies the UTI for the syntax highlighting.

Examples:

`xcode.lang.ruby`

Returns:

  • (String)

    a string that specifies the UTI for the syntax highlighting.



64
# File 'lib/xcodeproj/project/object/file_reference.rb', line 64

attribute :xc_language_specification_identifier, String

Instance Method Details

#build_filesArray<PBXBuildFile>

Returns the build files associated with the current file reference.

Returns:

  • (Array<PBXBuildFile>)

    the build files associated with the current file reference.



215
216
217
# File 'lib/xcodeproj/project/object/file_reference.rb', line 215

def build_files
  referrers.grep(PBXBuildFile)
end

#display_nameString

Returns the name of the file taking into account the path if needed.

Returns:

  • (String)

    the name of the file taking into account the path if needed.



133
134
135
136
137
138
139
140
141
# File 'lib/xcodeproj/project/object/file_reference.rb', line 133

def display_name
  if name
    name
  elsif (class << GroupableHelper; self; end)::SOURCE_TREES_BY_KEY[:built_products] == source_tree
    path
  elsif path
    File.basename(path)
  end
end

#file_reference_proxiesArray<PBXReferenceProxy>

If this file reference represents an external Xcode project reference then this will return proxies for file references contained in the external Xcode project.

Returns:

  • (Array<PBXReferenceProxy>)

    The file reference proxies for items located in the external Xcode project.



292
293
294
295
296
297
298
299
300
301
302
# File 'lib/xcodeproj/project/object/file_reference.rb', line 292

def file_reference_proxies
  containers = proxy_containers
  if containers.empty?
    []
  else
    project.objects.select do |object|
      object.isa == 'PBXReferenceProxy' &&
        containers.include?(object.remote_ref)
    end
  end
end

#full_pathPathname

source tree.

Returns:

  • (Pathname)

    the path of the file without resolving the



183
184
185
# File 'lib/xcodeproj/project/object/file_reference.rb', line 183

def full_path
  GroupableHelper.full_path(self)
end

#hierarchy_pathString

Returns A representation of the reference hierarchy.

Returns:

  • (String)

    A representation of the reference hierarchy.



158
159
160
# File 'lib/xcodeproj/project/object/file_reference.rb', line 158

def hierarchy_path
  GroupableHelper.hierarchy_path(self)
end

#move(new_parent) ⇒ void

This method returns an undefined value.

Moves the reference to a new parent.

Parameters:

  • new_parent (PBXGroup)

    The new parent.



169
170
171
# File 'lib/xcodeproj/project/object/file_reference.rb', line 169

def move(new_parent)
  GroupableHelper.move(self, new_parent)
end

#parentPBXGroup, PBXProject

Returns the parent of the file.

Returns:



145
146
147
# File 'lib/xcodeproj/project/object/file_reference.rb', line 145

def parent
  GroupableHelper.parent(self)
end

#parentsArray<PBXGroup, PBXProject>

Returns The list of the parents of the reference.

Returns:



152
153
154
# File 'lib/xcodeproj/project/object/file_reference.rb', line 152

def parents
  GroupableHelper.parents(self)
end

#project_reference_metadataObjectDictionary?

If this file reference represents an external Xcode project reference then this will return metadata about it which includes the reference to the ‘Products’ group that’s created in this project (the project that includes the external project).

Returns:

  • (ObjectDictionary, nil)

    The external project metadata for this file reference or ‘nil` if it’s not an external project.



265
266
267
268
269
# File 'lib/xcodeproj/project/object/file_reference.rb', line 265

def 
  project.root_object.project_references.find do |project_reference|
    project_reference[:project_ref] == self
  end
end

#proxy?Bool

Checks whether the reference is a proxy.

Returns:

  • (Bool)

    always false for this ISA.



253
254
255
# File 'lib/xcodeproj/project/object/file_reference.rb', line 253

def proxy?
  false
end

#proxy_containersArray<PBXContainerItemProxy>

If this file reference represents an external Xcode project reference then this will return the objects that are ‘containers’ for items contained in the external Xcode project.

Returns:



278
279
280
281
282
283
# File 'lib/xcodeproj/project/object/file_reference.rb', line 278

def proxy_containers
  project.objects.select do |object|
    object.isa == 'PBXContainerItemProxy' &&
      object.container_portal == uuid
  end
end

#real_pathPathname

source tree.

Returns:

  • (Pathname)

    the absolute path of the file resolving the



176
177
178
# File 'lib/xcodeproj/project/object/file_reference.rb', line 176

def real_path
  GroupableHelper.real_path(self)
end

#remove_from_projectvoid

This method returns an undefined value.

In addition to removing the file reference, this will also remove any items related to this reference.



330
331
332
333
334
335
336
337
338
339
340
# File 'lib/xcodeproj/project/object/file_reference.rb', line 330

def remove_from_project
  if project_reference = 
    file_reference_proxies.each(&:remove_from_project)
    target_dependency_proxies.each(&:remove_from_project)
    project_reference[:product_group].remove_from_project
    project.root_object.project_references.delete(project_reference)
  end

  build_files.each(&:remove_from_project)
  super
end

#set_explicit_file_type(type = nil) ⇒ void

This method returns an undefined value.

Sets the explicit file type according to the extension of the path, and clears the last known file type.



237
238
239
240
241
242
243
244
245
# File 'lib/xcodeproj/project/object/file_reference.rb', line 237

def set_explicit_file_type(type = nil)
  self.last_known_file_type = nil
  if type
    self.explicit_file_type = type
  elsif path
    extension = Pathname(path).extname[1..-1]
    self.explicit_file_type = Constants::FILE_TYPES_BY_EXTENSION[extension]
  end
end

#set_last_known_file_type(type = nil) ⇒ void

This method returns an undefined value.

Sets the last known file type according to the extension of the path.



223
224
225
226
227
228
229
230
# File 'lib/xcodeproj/project/object/file_reference.rb', line 223

def set_last_known_file_type(type = nil)
  if type
    self.last_known_file_type = type
  elsif path
    extension = Pathname(path).extname[1..-1]
    self.last_known_file_type = Constants::FILE_TYPES_BY_EXTENSION[extension]
  end
end

#set_path(path) ⇒ void

This method returns an undefined value.

Allows to set the path according to the source tree of the reference.

Parameters:

  • the (#to_s)

    path for the reference.



204
205
206
207
208
209
210
# File 'lib/xcodeproj/project/object/file_reference.rb', line 204

def set_path(path)
  if path
    GroupableHelper.set_path_with_source_tree(self, path, source_tree)
  else
    self.path = nil
  end
end

#set_source_tree(source_tree) ⇒ void

This method returns an undefined value.

Sets the source tree of the reference.

Parameters:

  • source_tree (Symbol, String)

    The source tree, either a string or a symbol.



194
195
196
# File 'lib/xcodeproj/project/object/file_reference.rb', line 194

def set_source_tree(source_tree)
  GroupableHelper.set_source_tree(self, source_tree)
end

#target_dependency_proxiesArray<PBXTargetDependency>

If this file reference represents an external Xcode project reference then this will return dependencies on targets contained in the external Xcode project.

Returns:

  • (Array<PBXTargetDependency>)

    The dependencies on targets located in the external Xcode project.



311
312
313
314
315
316
317
318
319
320
321
# File 'lib/xcodeproj/project/object/file_reference.rb', line 311

def target_dependency_proxies
  containers = proxy_containers
  if containers.empty?
    []
  else
    project.objects.select do |object|
      object.isa == 'PBXTargetDependency' &&
        containers.include?(object.target_proxy)
    end
  end
end