Last active
August 29, 2015 14:01
-
-
Save yasuoza/b3e35066b3f6b0e699c0 to your computer and use it in GitHub Desktop.
add file to xcode project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# FYI: | |
# http://www.j7lg.com/archives/1732 | |
require 'xcodeproj' | |
def bail_if_nil(obj, msg) | |
return unless obj.nil? | |
puts msg | |
exit | |
end | |
def remove_first_path_component(path) | |
arr = path.split('/') | |
arr.delete_at(0) | |
arr.join('/') | |
end | |
def find_subpath_from_main_group(project, group, name, path) | |
project.main_group.find_subpath(path, true); | |
end | |
if (ARGV.length < 3) | |
puts 'Usage: ' + $0 + ' <Project Name> <Group Name> <File Name>' | |
exit | |
end | |
project = Xcodeproj::Project.open(ARGV[0] + '.xcodeproj') | |
target = project.targets.find { |element| element.name == ARGV[0] } | |
bail_if_nil(target, ARGV[0] + ' target not found.') | |
group = project.main_group.find_subpath(ARGV[1], true); # create new group if it does not exist | |
bail_if_nil(group, ARGV[1] + ' group not found.') | |
target.add_file_references([group.new_file(ARGV[2])]) | |
project.save | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment