class Xcodeproj::XCScheme


folder.
usually stored in a xcuserdata or xcshareddata (for a shared scheme)
This class represents a Scheme document represented by a “.xcscheme” file

def self.share_scheme(project_path, scheme_name, user = nil)

Parameters:
  • user (String) --
  • scheme_name (String) --
  • project_path (String) --
def self.share_scheme(project_path, scheme_name, user = nil)
  to_folder = shared_data_dir(project_path)
  to_folder.mkpath
  to = to_folder + "#{scheme_name}.xcscheme"
  from = user_data_dir(project_path, user) + "#{scheme_name}.xcscheme"
  FileUtils.mv(from, to)
end

def self.shared_data_dir(project_path)

Returns:
  • (Pathname) -
def self.shared_data_dir(project_path)
  project_path = Pathname.new(project_path)
  project_path + 'xcshareddata/xcschemes'
end

def self.user_data_dir(project_path, user = nil)

Returns:
  • (Pathname) -
def self.user_data_dir(project_path, user = nil)
  project_path = Pathname.new(project_path)
  user ||= ENV['USER']
  project_path + "xcuserdata/#{user}.xcuserdatad/xcschemes"
end

def add_build_target(build_target, build_for_running = true)

Parameters:
  • build_for_running (Bool) --
  • build_target (Xcodeproj::Project::Object::AbstractTarget) --
def add_build_target(build_target, build_for_running = true)
  unless @build_action_entries
    @build_action_entries = @build_action.add_element 'BuildActionEntries'
  end
  build_action_entry = @build_action_entries.add_element 'BuildActionEntry'
  build_action_entry.attributes['buildForTesting'] = 'YES'
  build_action_entry.attributes['buildForRunning'] = build_for_running ? 'YES' : 'NO'
  build_action_entry.attributes['buildForProfiling'] = 'YES'
  build_action_entry.attributes['buildForArchiving'] = 'YES'
  build_action_entry.attributes['buildForAnalyzing'] = 'YES'
  buildable_reference = build_action_entry.add_element 'BuildableReference'
  buildable_reference.attributes['BuildableIdentifier'] = 'primary'
  buildable_reference.attributes['BlueprintIdentifier'] = build_target.uuid
  buildable_reference.attributes['BuildableName'] = construct_buildable_name(build_target)
  buildable_reference.attributes['BlueprintName'] = build_target.name
  buildable_reference.attributes['ReferencedContainer'] = construct_referenced_container_uri(build_target)
end

def add_test_target(test_target)

Parameters:
  • test_target (Xcodeproj::Project::Object::AbstractTarget) --
def add_test_target(test_target)
  testable_reference = @testables.add_element 'TestableReference'
  testable_reference.attributes['skipped'] = 'NO'
  buildable_reference = testable_reference.add_element 'BuildableReference'
  buildable_reference.attributes['BuildableIdentifier'] = 'primary'
  buildable_reference.attributes['BlueprintIdentifier'] = test_target.uuid
  buildable_reference.attributes['BuildableName'] = "#{test_target.name}.octest"
  buildable_reference.attributes['BlueprintName'] = test_target.name
  buildable_reference.attributes['ReferencedContainer'] = construct_referenced_container_uri(test_target)
end

def construct_buildable_name(build_target)

Returns:
  • (String) - The buildable name of the scheme.

Parameters:
  • target (Xcodeproj::Project::Object::AbstractTarget) --
def construct_buildable_name(build_target)
  case build_target.isa
  when 'PBXNativeTarget'
    File.basename(build_target.product_reference.path)
  when 'PBXAggregateTarget'
    build_target.name
  else
    raise ArgumentError, "Unsupported build target type #{build_target.isa}"
  end
end

def construct_referenced_container_uri(target)

Returns:
  • (String) - A string in the format "container:[path to the project

Parameters:
  • target (Xcodeproj::Project::Object::AbstractTarget) --
def construct_referenced_container_uri(target)
  project = target.project
  relative_path = project.path.relative_path_from(project.path + project.root_object.project_dir_path).to_s
  relative_path = project.path.basename if relative_path == '.'
  "container:#{relative_path}"
end

def initialize


Create a new XCScheme instance
def initialize
  @doc = REXML::Document.new
  @doc << REXML::XMLDecl.new(REXML::XMLDecl::DEFAULT_VERSION, 'UTF-8')
  @doc.context[:attribute_quote] = :quote
  @scheme = @doc.add_element 'Scheme'
  @scheme.attributes['LastUpgradeVersion'] = Constants::LAST_UPGRADE_CHECK
  @scheme.attributes['version'] = '1.3'
  @build_action = @scheme.add_element 'BuildAction'
  @build_action.attributes['parallelizeBuildables'] = 'YES'
  @build_action.attributes['buildImplicitDependencies'] = 'YES'
  @build_action_entries = nil
  @test_action = @scheme.add_element 'TestAction'
  @test_action.attributes['selectedDebuggerIdentifier'] = 'Xcode.DebuggerFoundation.Debugger.LLDB'
  @test_action.attributes['selectedLauncherIdentifier'] = 'Xcode.DebuggerFoundation.Launcher.LLDB'
  @test_action.attributes['shouldUseLaunchSchemeArgsEnv'] = 'YES'
  @test_action.attributes['buildConfiguration'] = 'Debug'
  @testables = @test_action.add_element 'Testables'
  @launch_action = @scheme.add_element 'LaunchAction'
  @launch_action.attributes['selectedDebuggerIdentifier'] = 'Xcode.DebuggerFoundation.Debugger.LLDB'
  @launch_action.attributes['selectedLauncherIdentifier'] = 'Xcode.DebuggerFoundation.Launcher.LLDB'
  @launch_action.attributes['launchStyle'] = '0'
  @launch_action.attributes['useCustomWorkingDirectory'] = 'NO'
  @launch_action.attributes['buildConfiguration'] = 'Debug'
  @launch_action.attributes['ignoresPersistentStateOnLaunch'] = 'NO'
  @launch_action.attributes['debugDocumentVersioning'] = 'YES'
  @launch_action.attributes['allowLocationSimulation'] = 'YES'
  @launch_action.add_element('AdditionalOptions')
  @profile_action = @scheme.add_element 'ProfileAction'
  @profile_action.attributes['shouldUseLaunchSchemeArgsEnv'] = 'YES'
  @profile_action.attributes['savedToolIdentifier'] = ''
  @profile_action.attributes['useCustomWorkingDirectory'] = 'NO'
  @profile_action.attributes['buildConfiguration'] = 'Release'
  @profile_action.attributes['debugDocumentVersioning'] = 'YES'
  analyze_action = @scheme.add_element 'AnalyzeAction'
  analyze_action.attributes['buildConfiguration'] = 'Debug'
  archive_action = @scheme.add_element 'ArchiveAction'
  archive_action.attributes['buildConfiguration'] = 'Release'
  archive_action.attributes['revealArchiveInOrganizer'] = 'YES'
end

def save_as(project_path, name, shared = true)

Other tags:
    Example: Saving a scheme -

Returns:
  • (void) -

Parameters:
  • shared (Boolean) --
  • name (String) --
  • project_path (String, Pathname) --
def save_as(project_path, name, shared = true)
  if shared
    scheme_folder_path = self.class.shared_data_dir(project_path)
  else
    scheme_folder_path = self.class.user_data_dir(project_path)
  end
  scheme_folder_path.mkpath
  scheme_path = scheme_folder_path + "#{name}.xcscheme"
  File.open(scheme_path, 'w') do |f|
    f.write(to_s)
  end
end

def set_launch_target(build_target)

Parameters:
  • build_target (Xcodeproj::Project::Object::AbstractTarget) --
def set_launch_target(build_target)
  launch_product_runnable = @launch_action.add_element 'BuildableProductRunnable'
  launch_buildable_reference = launch_product_runnable.add_element 'BuildableReference'
  launch_buildable_reference.attributes['BuildableIdentifier'] = 'primary'
  launch_buildable_reference.attributes['BlueprintIdentifier'] = build_target.uuid
  launch_buildable_reference.attributes['BuildableName'] = "#{build_target.name}.app"
  launch_buildable_reference.attributes['BlueprintName'] = build_target.name
  launch_buildable_reference.attributes['ReferencedContainer'] = construct_referenced_container_uri(build_target)
  profile_product_runnable = @profile_action.add_element 'BuildableProductRunnable'
  profile_buildable_reference = profile_product_runnable.add_element 'BuildableReference'
  profile_buildable_reference.attributes['BuildableIdentifier'] = 'primary'
  profile_buildable_reference.attributes['BlueprintIdentifier'] = build_target.uuid
  profile_buildable_reference.attributes['BuildableName'] = "#{build_target.name}.app"
  profile_buildable_reference.attributes['BlueprintName'] = build_target.name
  profile_buildable_reference.attributes['ReferencedContainer'] = construct_referenced_container_uri(build_target)
  macro_expansion = @test_action.add_element 'MacroExpansion'
  buildable_reference = macro_expansion.add_element 'BuildableReference'
  buildable_reference.attributes['BuildableIdentifier'] = 'primary'
  buildable_reference.attributes['BlueprintIdentifier'] = build_target.uuid
  buildable_reference.attributes['BuildableName'] = File.basename(build_target.product_reference.path)
  buildable_reference.attributes['BlueprintName'] = build_target.name
  buildable_reference.attributes['ReferencedContainer'] = construct_referenced_container_uri(build_target)
end

def to_s

Returns:
  • (String) - the XML string value of the current state of the object.

Other tags:
    Note: - The goal of the string representation is to match Xcode output as
def to_s
  formatter = XMLFormatter.new(2)
  formatter.compact = false
  out = ''
  formatter.write(@doc, out)
  out.gsub!("<?xml version='1.0' encoding='UTF-8'?>", '<?xml version="1.0" encoding="UTF-8"?>')
  out << "\n"
  out
end