class Xcodeproj::Project::Object::AbstractPBXObject

def self.attribute(name, options = {})

Options Hash: (**options)
  • :as (Symbol String) -- An optional custom name for

Parameters:
  • attribute_name (Symbol, String) -- The key in snake case.
def self.attribute(name, options = {})
  accessor_name  = (options[:as] || name).to_s
  attribute_name = name.to_s.camelize(:lower) # change `foo_bar' to `fooBar'
  define_method(accessor_name) { @attributes[attribute_name] }
  define_method("#{accessor_name}=") { |value| @attributes[attribute_name] = value }
end

def self.create_reflection(type, name, options)

def self.create_reflection(type, name, options)
  (reflections << Association::Reflection.new(type, name, options)).last
end

def self.isa

def self.isa
  @isa ||= name.split('::').last
end

def self.reflection(name)

def self.reflection(name)
  reflections.find { |r| r.name.to_s == name.to_s }
end

def self.reflections

def self.reflections
  @reflections ||= []
end

def <=>(other)

def <=>(other)
  self.uuid <=> other.uuid
end

def ==(other)

def ==(other)
  other.is_a?(AbstractPBXObject) && self.uuid == other.uuid
end

def create_association(type, name, options, &block)

def create_association(type, name, options, &block)
  reflection = create_reflection(type, name, options)
  unless reflection.inverse?
    attribute(reflection.attribute_name, :as => reflection.attribute_getter)
  end
  define_method(reflection.getter) do
    reflection.association_for(self, &block).get
  end
  define_method(reflection.setter) do |new_value|
    reflection.association_for(self, &block).set(new_value)
  end
end

def destroy

def destroy
  @project.objects_hash.delete(uuid)
end

def generate_uuid

UUID in the xcodeproj extension doesn't cause a collision.
Generate a truly unique UUID. This is to ensure that cutting up the
def generate_uuid
  begin
    uuid = Xcodeproj.generate_uuid
  end while @project.objects_hash.has_key?(uuid)
  uuid
end

def has_many(plural_attr_name, options = {}, &block)

def has_many(plural_attr_name, options = {}, &block)
  create_association(:has_many, plural_attr_name, options, &block)
end

def has_one(singular_attr_name, options = {})

def has_one(singular_attr_name, options = {})
  create_association(:has_one, singular_attr_name, options)
end

def initialize(project, uuid, attributes)

Returns:
  • (AbstractPBXObject) -
def initialize(project, uuid, attributes)
  @project, @attributes = project, attributes
  self.isa ||= self.class.isa
  unless uuid
    # Add new objects to the main hash with a unique UUID
    uuid = generate_uuid
    @project.add_object_hash(uuid, @attributes)
  end
  @uuid = uuid
end

def inspect

def inspect
  "#<#{isa} UUID: `#{uuid}', name: `#{name}'>"
end

def list_by_class(uuid_list, klass)

Returns:
  • (PBXObjectList) - The list of matching objects.

Other tags:
    Yield: - The list instance, allowing you to

Parameters:
  • klass (AbstractPBXObject) -- The AbstractPBXObject subclass to
  • uuid_list (Array) -- The UUID array instance which is
def list_by_class(uuid_list, klass)
  PBXObjectList.new(klass, @project) do |list|
    list.let(:uuid_scope) do
      # TODO why does this not work? should be more efficient.
      #uuid_list.select do |uuid|
        #@project.objects_hash[uuid]['isa'] == klass.isa
      #end
      uuid_list.map { |uuid| @project.objects[uuid] }.select { |o| o.is_a?(klass) }.map(&:uuid)
    end
    list.let(:push) do |new_object|
      # Add the uuid of a newly created object to the uuids list
      uuid_list << new_object.uuid
    end
    yield list if block_given?
  end
end

def matches_attributes?(attributes)

def matches_attributes?(attributes)
  attributes.all? do |attribute, expected_value|
    return nil unless respond_to?(attribute)
    if expected_value.is_a?(Hash)
      send(attribute).matches_attributes?(expected_value)
    else
      send(attribute) == expected_value
    end
  end
end