class Xcodeproj::XCScheme


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

def self.share_scheme(project_path, scheme_name, user = ENV['USER'])

Parameters:
  • user (String) -- The user name that have the scheme
  • scheme_name (String) -- The name of scheme that will be shared.
  • project_path (String) -- Path of the .xcodeproj folder.
def self.share_scheme(project_path, scheme_name, user = ENV['USER'])
  from = File.join project_path, 'xcuserdata', "#{user}.xcuserdatad", 'xcschemes', "#{scheme_name}.xcscheme"
  to_folder = File.join project_path, 'xcshareddata', 'xcschemes'
  Pathname(to_folder).mkpath
  to = File.join to_folder, "#{scheme_name}.xcscheme"
  FileUtils.mv from, to
end

def build_target_for_running=(build_target_for_running)

Parameters:
  • build_target_for_running (Boolean) --
def build_target_for_running=(build_target_for_running)
  build_action = @doc.root.elements['BuildAction']
  
  if (build_action.elements['BuildActionEntries'] == nil) then
    build_action_entries = build_action.add_element 'BuildActionEntries'
  else
    build_action_entries = build_action.elements['BuildActionEntries']
  end
  
  if (build_action_entries.elements['BuildActionEntry'] == nil) then
    build_action_entry = build_action_entries.add_element 'BuildActionEntry'
    build_action_entry.attributes['buildForTesting'] = 'YES'
    build_action_entry.attributes['buildForProfiling'] = 'NO'
    build_action_entry.attributes['buildForArchiving'] = 'NO'
    build_action_entry.attributes['buildForAnalyzing'] = 'NO'
  else
    build_action_entry = build_action_entries.elements['BuildActionEntry']
  end
  
  build_action_entry.attributes['buildForRunning'] = build_target_for_running ? 'YES' : 'NO'
  
  if (build_action_entry.elements['BuildableReference'] == nil) then
    buildable_reference = build_action_entry.add_element 'BuildableReference'
    buildable_reference.attributes['BuildableIdentifier'] = 'primary'
    buildable_reference.attributes['BlueprintIdentifier'] = build_target.uuid
    buildable_reference.attributes['BuildableName'] = "#{build_target.name}.octest"
    buildable_reference.attributes['BlueprintName'] = build_target.name
    buildable_reference.attributes['ReferencedContainer'] = "container:#{container}.xcodeproj"
  end
end

def build_target_for_running?

Returns:
  • (Boolean) -
def build_target_for_running?
  build_target_for_running = ''
  if build_action = @doc.root.elements['BuildAction']
    if build_action_entries = build_action.elements['BuildActionEntries']
      if build_action_entry = build_action_entries.elements['BuildActionEntry']
        build_target_for_running = build_action_entry.attributes['buildForRunning']
      end
    end
  end
  build_target_for_running == 'YES'
end

def initialize(container, build_target, test_target = nil)

Parameters:
  • test_target (Xcodeproj::Project::Object::AbstractTarget) --
  • build_target (Xcodeproj::Project::Object::AbstractTarget) --
  • container (String) --
def initialize(container, build_target, test_target = nil)
  @container = container
  @build_target = build_target
  @test_target = test_target
  
  @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'] = build_target.project.root_object.attributes['LastUpgradeCheck']
  scheme.attributes['version'] = '1.3'
  
  build_action = scheme.add_element 'BuildAction'
  build_action.attributes['parallelizeBuildables'] = 'YES'
  build_action.attributes['buildImplicitDependencies'] = 'YES'
  
  if (build_target.product_type == 'com.apple.product-type.application') then
    build_action_entries = build_action.add_element 'BuildActionEntries'
    
    build_action_entry = build_action_entries.add_element 'BuildActionEntry'
    build_action_entry.attributes['buildForTesting'] = 'YES'
    build_action_entry.attributes['buildForRunning'] = 'YES'
    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'] = "#{build_target.name}.app"
    buildable_reference.attributes['BlueprintName'] = build_target.name
    buildable_reference.attributes['ReferencedContainer'] = "container:#{container}.xcodeproj"
  end
  
  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'
  if (test_target != nil) then
    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'] = "container:#{container}.xcodeproj"
    if (build_target.product_type == 'com.apple.product-type.application') then
      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'] = "#{build_target.name}.app"
      buildable_reference.attributes['BlueprintName'] = build_target.name
      buildable_reference.attributes['ReferencedContainer'] = "container:#{container}.xcodeproj"
    end
  end
  
  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'
  
  if (build_target.product_type == 'com.apple.product-type.application') then
    buildable_product_runnable = launch_action.add_element 'BuildableProductRunnable'
  
    buildable_reference = buildable_product_runnable.add_element 'BuildableReference'
    buildable_reference.attributes['BuildableIdentifier'] = 'primary'
    buildable_reference.attributes['BlueprintIdentifier'] = build_target.uuid
    buildable_reference.attributes['BuildableName'] = "#{build_target.name}.app"
    buildable_reference.attributes['BlueprintName'] = build_target.name
    buildable_reference.attributes['ReferencedContainer'] = "container:#{container}.xcodeproj"
  end
  
  additional_options = 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'
  
  if (build_target.product_type == 'com.apple.product-type.application') then
    buildable_product_runnable = profile_action.add_element 'BuildableProductRunnable'
  
    buildable_reference = buildable_product_runnable.add_element 'BuildableReference'
    buildable_reference.attributes['BuildableIdentifier'] = 'primary'
    buildable_reference.attributes['BlueprintIdentifier'] = build_target.uuid
    buildable_reference.attributes['BuildableName'] = "#{build_target.name}.app"
    buildable_reference.attributes['BlueprintName'] = build_target.name
    buildable_reference.attributes['ReferencedContainer'] = "container:#{container}.xcodeproj"
  end
  
  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, shared = true)

Other tags:
    Example: Saving a scheme -

Returns:
  • (void) -

Parameters:
  • shared (Boolean) --
  • project_path (String, Pathname) --
def save_as(project_path, shared = true)
  if shared then
    scheme_folder_path = File.join(project_path, 'xcshareddata', 'xcschemes')
  else
    scheme_folder_path = File.join(project_path, 'xcuserdata', "#{ENV['USER']}.xcuserdatad", 'xcschemes')
  end
  Pathname(scheme_folder_path).mkpath
  scheme_path = File.join(scheme_folder_path, "#{build_target.display_name}.xcscheme")
  File.open(scheme_path, 'w') do |f|
    f.write(self)
  end
end

def to_s

Returns:
  • (String) - the XML string value of the current state of the object
def to_s
  formatter = REXML::Formatters::Pretty.new(2)
  formatter.compact = true
  out = ''
  formatter.write(@doc, out)
  out
end