class Xcodeproj::Project::Object::PBXGroup


(PBXGroup) and file references (PBXFileReference).
This class represents a group. A group can contain other groups

def <<(child)

Returns:
  • (ObjectList) - the children list.
def <<(child)
  children << child
end

def [](path)

Other tags:
    See: find_subpath -
def [](path)
  find_subpath(path, false)
end

def ascii_plist_annotation

def ascii_plist_annotation
  super unless self.equal?(project.main_group)
end

def clear


Removes children files and groups under this group.
def clear
  children.objects.each(&:remove_from_project)
end

def display_name

Returns:
  • (String) - the name of the group taking into account the path
def display_name
  if name
    name
  elsif path
    File.basename(path)
  elsif self.equal?(project.main_group)
    'Main Group'
  end
end

def empty?

Returns:
  • (Bool) - Whether the group is empty.
def empty?
  children.count.zero?
end

def files

Returns:
  • (Array) - the file references in the group
def files
  children.grep(PBXFileReference)
end

def find_file_by_path(path)

Returns:
  • (PBXFileReference) - The file references whose path (regardless
def find_file_by_path(path)
  files.find { |ref| ref.path == path }
end

def find_subpath(path, should_create = false)

Returns:
  • (Nil) - if the path could not be found and should create is
  • (PBXGroup) - the group if found.

Other tags:
    Note: - The path is matched against the {#display_name} of the groups.

Parameters:
  • should_create (Boolean) --
  • path (String) --
def find_subpath(path, should_create = false)
  return self unless path
  path = path.split('/') unless path.is_a?(Array)
  child_name = path.shift
  child = children.find { |c| c.display_name == child_name }
  if child.nil?
    if should_create
      child = new_group(child_name)
    else
      return nil
    end
  end
  if path.empty?
    child
  else
    child.find_subpath(path, should_create)
  end
end

def groups

Returns:
  • (Array) - the groups in the group children.
def groups
  # Don't grep / is_a? as this would include child classes.
  children.select { |obj| obj.class == PBXGroup }
end

def hierarchy_path

Returns:
  • (String) - A representation of the group hierarchy.
def hierarchy_path
  GroupableHelper.hierarchy_path(self)
end

def move(new_parent)

Returns:
  • (void) -

Parameters:
  • new_parent (PBXGroup) --
def move(new_parent)
  GroupableHelper.move(self, new_parent)
end

def new_bundle(product_name)

Returns:
  • (PBXFileReference) - The new file reference.

Parameters:
  • product_name (#to_s) --
def new_bundle(product_name)
  FileReferencesFactory.new_bundle(self, product_name)
end

def new_group(name, path = nil, source_tree = :group)

Returns:
  • (PBXGroup) - the new group.

Parameters:
  • name (#to_s) --

Other tags:
    Note: - @see new_reference
def new_group(name, path = nil, source_tree = :group)
  group = project.new(PBXGroup)
  children << group
  group.name = name
  group.set_source_tree(source_tree)
  group.set_path(path)
  group
end

def new_product_ref_for_target(target_name, product_type)

Returns:
  • (PBXFileReference) - The new file reference.

Parameters:
  • product_name (#to_s) --
def new_product_ref_for_target(target_name, product_type)
  FileReferencesFactory.new_product_ref_for_target(self, target_name, product_type)
end

def new_reference(path, source_tree = :group)

Returns:
  • (PBXFileReference, XCVersionGroup) - The new reference.

Parameters:
  • source_tree (Symbol) --
  • path (#to_s) --
def new_reference(path, source_tree = :group)
  FileReferencesFactory.new_reference(self, path, source_tree)
end

def new_variant_group(name, path = nil, source_tree = :group)

Returns:
  • (PBXVariantGroup) - the new variant group.

Parameters:
  • source_tree (Symbol) --
  • path (#to_s) --
  • name (#to_s) --

Other tags:
    Note: - @see new_group
def new_variant_group(name, path = nil, source_tree = :group)
  group = project.new(PBXVariantGroup)
  children << group
  group.name = name
  group.set_source_tree(source_tree)
  group.set_path(path)
  group
end

def parent

Returns:
  • (PBXGroup, PBXProject) - The parent of the group.
def parent
  GroupableHelper.parent(self)
end

def parents

Returns:
  • (Array) - The list of the parents of the
def parents
  GroupableHelper.parents(self)
end

def real_path

Returns:
  • (Pathname) - the absolute path of the group resolving the
def real_path
  GroupableHelper.real_path(self)
end

def recursive_children

Returns:
  • (Array) - the
def recursive_children
  result = []
  children.each do |child|
    result << child
    if child.is_a?(PBXGroup)
      result.concat(child.recursive_children)
    end
  end
  result
end

def recursive_children_groups

Returns:
  • (Array) - the
def recursive_children_groups
  result = []
  groups.each do |child|
    result << child
    result.concat(child.recursive_children_groups)
  end
  result
end

def set_path(path)

Returns:
  • (void) -

Parameters:
  • the (#to_s) -- path for the group.
def set_path(path)
  if path
    source_tree
    GroupableHelper.set_path_with_source_tree(self, path, source_tree)
  else
    self.path = nil
    self.source_tree = '<group>'
  end
end

def set_source_tree(source_tree)

Returns:
  • (void) -

Parameters:
  • source_tree (Symbol, String) --
def set_source_tree(source_tree)
  GroupableHelper.set_source_tree(self, source_tree)
end

def sort(options = nil)

Returns:
  • (void) -

Options Hash: (**options)
  • :groups_position (Symbol) --

Parameters:
  • options (Hash) --
def sort(options = nil)
  children.sort! do |x, y|
    if options && groups_position = options[:groups_position]
      raise ArgumentError unless [:above, :below].include?(groups_position)
      if x.isa == 'PBXGroup' && !(y.isa == 'PBXGroup')
        next groups_position == :above ? -1 : 1
      elsif !(x.isa == 'PBXGroup') && y.isa == 'PBXGroup'
        next groups_position == :above ? 1 : -1
      end
    end
    result = File.basename(x.display_name.downcase, '.*') <=> File.basename(y.display_name.downcase, '.*')
    if result.zero?
      File.extname(x.display_name.downcase) <=> File.extname(y.display_name.downcase)
    else
      result
    end
  end
end

def sort_by_type

Returns:
  • (void) -

Other tags:
    Note: - This is safe to call in an object list because it modifies it
def sort_by_type
  children.sort! do |x, y|
    if x.isa == 'PBXGroup' && !(y.isa == 'PBXGroup')
      -1
    elsif !(x.isa == 'PBXGroup') && y.isa == 'PBXGroup'
      1
    elsif x.display_name && y.display_name
      extname_x = File.extname(x.display_name)
      extname_y = File.extname(y.display_name)
      if extname_x != extname_y
        extname_x <=> extname_y
      else
        File.basename(x.display_name, '.*') <=> File.basename(y.display_name, '.*')
      end
    else
      0
    end
  end
end

def sort_recursively_by_type

Returns:
  • (void) -
def sort_recursively_by_type
  groups.each(&:sort_recursively_by_type)
  sort_by_type
end

def version_groups

Returns:
  • (Array) - the version groups in the group
def version_groups
  children.grep(XCVersionGroup)
end