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:
    Note: -

Parameters:
  • path () --
def [](path)
  find_subpath(path)
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 files

Returns:
  • (Array) - the files references in the group
def files
  children.select { |obj| obj.class == PBXFileReference }
end

def find_subpath(path, should_create = false)

Returns:
  • (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 }
  child = new_group(child_name) if child.nil? && should_create
  if path.empty?
    child
  else
    child.find_subpath(path, should_create)
  end
end

def groups

Returns:
  • (Array) - the groups in the group
def groups
  children.select { |obj| obj.class == PBXGroup }
end

def new_file(path, sub_group_path = nil)

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

Parameters:
  • sub_group_path (String) --
  • path (#to_s) --

Other tags:
    Note: - The subpath is created if needed, similar to the UNIX command `mkdir -p`
def new_file(path, sub_group_path = nil)
  file = project.new(PBXFileReference)
  file.path = path.to_s
  file.name = file.pathname.basename.to_s
  file.update_last_known_file_type
  target = find_subpath(sub_group_path, true)
  target.children << file
  file
end

def new_group(name, sub_group_path = nil)

Returns:
  • (PBXGroup) - the new group.

Parameters:
  • sub_group_path (String) -- (see #new_file)
  • name (#to_s) --

Other tags:
    Note: -
def new_group(name, sub_group_path = nil)
  group = project.new(PBXGroup)
  group.name = name
  target = find_subpath(sub_group_path, true)
  target.children << group
  group
end

def new_static_library(product_name, sub_group_path = nil)

Returns:
  • (PBXFileReference) - the new group.

Parameters:
  • sub_group_path (String) -- (see #new_file)#
  • product_name (#to_s) --

Other tags:
    Note: -
def new_static_library(product_name, sub_group_path = nil)
  file = new_file("lib#{product_name}.a", sub_group_path)
  file.include_in_index = '0'
  file.source_tree = 'BUILT_PRODUCTS_DIR'
  file.explicit_file_type = file.last_known_file_type
  file.last_known_file_type = nil
  file
end

def new_xcdatamodel_group(xcdatamodel_path)

Returns:
  • (XCVersionGroup) - The new group.
def new_xcdatamodel_group(xcdatamodel_path)
  g = @project.new(XCVersionGroup)
  g.path = xcdatamodel_path
  g.version_group_type = 'wrapper.xcdatamodel'
  file = g.new_file(xcdatamodel_path.sub(/xcdatamodeld$/, 'xcdatamodel'))
  g.current_version = file
  g
end

def remove_children_recursively


Removes children files and groups under this group.
def remove_children_recursively
  groups.each do |g|
    g.remove_children_recursively
    g.remove_from_project
  end
  files.each { |f| f.remove_from_project }
end

def sort_by_type

Returns:
  • (void) -
def sort_by_type
  children.sort do |x, y|
    if x.is_a?(PBXGroup) && y.is_a?(PBXFileReference)
      -1
    elsif x.is_a?(PBXFileReference) && y.is_a?(PBXGroup)
      1
    elsif x.respond_to?(:name) && y.respond_to?(:name)
      x.name <=> y.name
    else
      0
    end
  end
end

def version_groups

Returns:
  • (Array) - the version groups in the group
def version_groups
  children.select { |obj| obj.class == XCVersionGroup }
end