7

Is there a way to remove files from or add files to a XCode project without using XCode? That is, is there any terminal command or program to do it? I know I can do cp mv and rm to add / remove files but they are not reflected in the actual project file. Thanks!

2
  • I don't think so, but Xcode is AppleScript-able and can probably add/remove files that way. Commented Mar 26, 2014 at 1:29
  • 1
    If you know Ruby: github.com/CocoaPods/Xcodeproj Commented Mar 26, 2014 at 4:55

2 Answers 2

4

There's a Ruby Gem called xcodeproj which allows manipulation of an XCodeProject at the command line.

Check out Using the Xcodeproj Ruby Gem which provides an example of adding a file to a project.

# Open the existing Xcode project
project_file = product_name + '.xcodeproj'
project = Xcodeproj::Project.new(project_file)

# Add a file to the project in the main group
file_name = 'Message.m'
group_name = product_name
file = project.new_file(file_name, group_name)

# Add the file to the main target
main_target = project.targets.first
main_target.add_file_references([file])

# Save the project file
project.save_as(project_file)
Sign up to request clarification or add additional context in comments.

Comments

0

try building after you copy them in using this

don't know if it will work, but worth a try :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.