CocoaPods / Xcodeproj

Create and modify Xcode projects from Ruby.
http://rubygems.org/gems/xcodeproj
MIT License
2.36k stars 458 forks source link

How to use it to add files to xcodeproj #266

Closed draveness closed 9 years ago

draveness commented 9 years ago

I google this but didn't find any pieces of code can run. And I find nothing in this document about this...And what is the source_tree is it a group?

orta commented 9 years ago

Here's an example of finding/creating a group, then adding a file to it: https://github.com/CocoaPods/cocoapods-acknowledgements/blob/master/lib/cocoapods_acknowledgements.rb#L8-L26

draveness commented 9 years ago

Thx a lot!

draveness commented 9 years ago

Why do I add files with this code, the compiler remind me file not exist? Is the file path relative to the root folder?

I use these code to add files to target but every time, the compiler path is wrong it is prefix with pod/classes

def add_files_to_project(path, json_path)
    j = JSON.parse File.read(json_path)
    project = Xcodeproj::Project.open(path)
    target = project.targets.first

    group_path = 'DKNightVersion/Pod/Classes/UIKit'
    j.each do |group, files|
        new_group = project.main_group.find_subpath(File.join(group_path, group), true)
        file_refs = []
        files.each do |f|
            file_ref = new_group.new_reference(f)            
            file_refs << file_ref
        end
        target.add_file_references(file_refs)
    end
    project.save
end

88b0e6ad-f285-4546-84c3-917d7ba35201 323f5e01-a54d-484f-9831-d7a966c39bd6 3cfe120a-a6f8-4932-b7e2-1ad7fbe2d36b c0de3edf-e934-44eb-bec4-0af6ec4a9513

draveness commented 9 years ago

I find these file are not in compile sources how can I add these files to it..

orta commented 9 years ago

you also have to add it to the build phases alas

draveness commented 9 years ago

I have already fix it. Because I didn't set the source tree to SOURCE_ROOT