class Xcodeproj::Project::Object::PBXFileReference

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

Public Instance Methods

build_files() click to toggle source

@return [Array<PBXBuildFile>] the build files associated with the

current file reference.
# File lib/xcodeproj/project/object/file_reference.rb, line 215
def build_files
  referrers.grep(PBXBuildFile)
end
display_name() click to toggle source

@return [String] the name of the file taking into account the path if

needed.
# 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_proxies() click to toggle source

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

@return [Array<PBXReferenceProxy>] The file reference proxies for

items located in the external Xcode project.
# 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_path() click to toggle source

@return [Pathname] the path of the file without resolving the source tree.

# File lib/xcodeproj/project/object/file_reference.rb, line 183
def full_path
  GroupableHelper.full_path(self)
end
hierarchy_path() click to toggle source

@return [String] A representation of the reference hierarchy.

# File lib/xcodeproj/project/object/file_reference.rb, line 158
def hierarchy_path
  GroupableHelper.hierarchy_path(self)
end
move(new_parent) click to toggle source

Moves the reference to a new parent.

@param [PBXGroup] new_parent

The new parent.

@return [void]

# File lib/xcodeproj/project/object/file_reference.rb, line 169
def move(new_parent)
  GroupableHelper.move(self, new_parent)
end
parent() click to toggle source

@return [PBXGroup, PBXProject] the parent of the file.

# File lib/xcodeproj/project/object/file_reference.rb, line 145
def parent
  GroupableHelper.parent(self)
end
parents() click to toggle source

@return [Array<PBXGroup, PBXProject>] The list of the parents of the

reference.
# File lib/xcodeproj/project/object/file_reference.rb, line 152
def parents
  GroupableHelper.parents(self)
end
project_reference_metadata() click to toggle source

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

@return [ObjectDictionary, nil] The external project metadata for

this file reference or `nil` if it's not an external project.
# File lib/xcodeproj/project/object/file_reference.rb, line 265
def project_reference_metadata
  project.root_object.project_references.find do |project_reference|
    project_reference[:project_ref] == self
  end
end
proxy?() click to toggle source

Checks whether the reference is a proxy.

@return [Bool] always false for this ISA.

# File lib/xcodeproj/project/object/file_reference.rb, line 253
def proxy?
  false
end
proxy_containers() click to toggle source

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.

@return [Array<PBXContainerItemProxy>] The containers for items in

the external Xcode project.
# 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_path() click to toggle source

@return [Pathname] the absolute path of the file resolving the source tree.

# File lib/xcodeproj/project/object/file_reference.rb, line 176
def real_path
  GroupableHelper.real_path(self)
end
remove_from_project() click to toggle source

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

@see AbstractObject#remove_from_project

@return [void]

# File lib/xcodeproj/project/object/file_reference.rb, line 330
def remove_from_project
  if project_reference = project_reference_metadata
    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) click to toggle source

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

@return [void]

# 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) click to toggle source

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

@return [void]

# 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) click to toggle source

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

@param [#to_s] the path for the reference.

@return [void]

# 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) click to toggle source

Sets the source tree of the reference.

@param [Symbol, String] source_tree

The source tree, either a string or a symbol.

@return [void]

# 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_proxies() click to toggle source

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

@return [Array<PBXTargetDependency>] The dependencies on targets

located in the external Xcode project.
# 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