Method: Xcode::Group#create_file

Defined in:
lib/xcode/group.rb

#create_file(file_properties) ⇒ FileReference

Add a file to the specified group. Currently the file creation requires the path to the physical file.

Examples:

creating a file with just a path


project.main_group.create_file 'AppDelegate.m'

creating a file with a name and path


project.main_group.create_file 'name' => 'AppDelegate.m', 'path' => 'Subfolder/AppDelegate.m'

Parameters:

  • path (String, Hash)

    to the file that is being added or a hash that contains the values would be merged with the default values.

Returns:



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/xcode/group.rb', line 140

def create_file(file_properties)
  # This allows both support for the string value or the hash as the parameter
  file_properties = { 'path' => file_properties } if file_properties.is_a? String
  
  # IF the file already exists then we will not create the file with the
  # parameters that are being supplied, instead we will return what we
  # found.
  
  find_file_by = file_properties['name'] || file_properties['path']
  
  found_or_created_file = exists?(find_file_by).first
  
  unless found_or_created_file
    found_or_created_file = create_child_object FileReference.file(file_properties)
  end
  
  found_or_created_file.supergroup = self
  
  found_or_created_file
end