Class: Xcodeproj::Project::Object::PBXNativeTarget

Inherits:
AbstractTarget show all
Defined in:
lib/xcodeproj/project/object/native_target.rb

Overview

Represents a target handled by Xcode.

Attributes (collapse)

Attributes inherited from AbstractTarget

#build_configuration_list, #comments, #name, #product_name

Attributes inherited from AbstractObject

#isa, #project, #uuid

Attributes (collapse)

Helpers (collapse)

AbstractObject Hooks (collapse)

Methods inherited from AbstractTarget

#add_build_configuration, #add_dependency, #add_system_framework, #add_system_library, #build_configurations, #build_settings, #common_resolved_build_setting, #copy_files_build_phases, #dependencies, #dependency_for_target, #deployment_target, #frameworks_build_phases, #new_copy_files_build_phase, #new_shell_script_build_phase, #platform_name, #pretty_print, #resolved_build_setting, #sdk, #sdk_version, #shell_script_build_phases

Methods inherited from AbstractObject

#<=>, #==, #display_name, #inspect, isa, #pretty_print, #remove_from_project, #sort_recursively, #to_hash

Instance Attribute Details

- (String) product_install_path



370
# File 'lib/xcodeproj/project/object/native_target.rb', line 370

attribute :product_install_path, String

- (PBXFileReference) product_reference



366
# File 'lib/xcodeproj/project/object/native_target.rb', line 366

has_one :product_reference, PBXFileReference

- (String) product_type



362
# File 'lib/xcodeproj/project/object/native_target.rb', line 362

attribute :product_type, String

Instance Method Details

- (Array<PBXBuildFile>) add_file_references(file_references, compiler_flags = {})

Adds source files to the target.



407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
# File 'lib/xcodeproj/project/object/native_target.rb', line 407

def add_file_references(file_references, compiler_flags = {})
  file_references.map do |file|
    build_file = project.new(PBXBuildFile)
    build_file.file_ref = file

    extension = File.extname(file.path)
    header_extensions = Constants::HEADER_FILES_EXTENSIONS
    if header_extensions.include?(extension)
      headers_build_phase.files << build_file
    else
      if compiler_flags && !compiler_flags.empty?
        build_file.settings = { 'COMPILER_FLAGS' => compiler_flags }
      end
      source_build_phase.files << build_file
    end

    yield build_file if block_given?

    build_file
  end
end

- (void) add_resources(resource_file_references)

This method returns an undefined value.

Adds resource files to the resources build phase of the target.



436
437
438
439
440
441
442
# File 'lib/xcodeproj/project/object/native_target.rb', line 436

def add_resources(resource_file_references)
  resource_file_references.each do |file|
    build_file = project.new(PBXBuildFile)
    build_file.file_ref = file
    resources_build_phase.files << build_file
  end
end

- (ObjectList<AbstractBuildPhase>) build_phases

Note:

Apparently only PBXCopyFilesBuildPhase and PBXShellScriptBuildPhase can appear multiple times in a target.

Returns the build phases of the target.



379
# File 'lib/xcodeproj/project/object/native_target.rb', line 379

has_many :build_phases, AbstractBuildPhase

- (PBXBuildRule) build_rules



358
# File 'lib/xcodeproj/project/object/native_target.rb', line 358

has_many :build_rules, PBXBuildRule

- (PBXFrameworksBuildPhase) frameworks_build_phase

Note:

A target should have only one frameworks build phase.

Finds or creates the frameworks build phase of the target.



470
471
472
# File 'lib/xcodeproj/project/object/native_target.rb', line 470

def frameworks_build_phase
  find_or_create_build_phase_by_class(PBXFrameworksBuildPhase)
end

- (PBXHeadersBuildPhase) headers_build_phase

Note:

A target should have only one headers build phase.

Finds or creates the headers build phase of the target.



450
451
452
# File 'lib/xcodeproj/project/object/native_target.rb', line 450

def headers_build_phase
  find_or_create_build_phase_by_class(PBXHeadersBuildPhase)
end

- (PBXResourcesBuildPhase) resources_build_phase

Note:

A target should have only one resources build phase.

Finds or creates the resources build phase of the target.



480
481
482
# File 'lib/xcodeproj/project/object/native_target.rb', line 480

def resources_build_phase
  find_or_create_build_phase_by_class(PBXResourcesBuildPhase)
end

- (Object) sort(_options = nil)

Sorts the to many attributes of the object according to the display name.

Build phases are not sorted as they order is relevant.



514
515
516
517
518
519
520
521
522
# File 'lib/xcodeproj/project/object/native_target.rb', line 514

def sort(_options = nil)
  attributes_to_sort = to_many_attributes.reject { |attr| attr.name == :build_phases }
  attributes_to_sort.each do |attrb|
    list = attrb.get_value(self)
    list.sort! do |x, y|
      x.display_name <=> y.display_name
    end
  end
end

- (PBXSourcesBuildPhase) source_build_phase

Note:

A target should have only one source build phase.

Finds or creates the source build phase of the target.



460
461
462
# File 'lib/xcodeproj/project/object/native_target.rb', line 460

def source_build_phase
  find_or_create_build_phase_by_class(PBXSourcesBuildPhase)
end

- (Symbol) symbol_type



388
389
390
391
392
# File 'lib/xcodeproj/project/object/native_target.rb', line 388

def symbol_type
  pair = Constants::PRODUCT_TYPE_UTI.find { |_key, value| value == product_type }
  return nil if pair.nil?
  pair.first
end