CocoaPods / Xcodeproj

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

Add entire folder to xcodeproj #178

Closed swl367 closed 9 years ago

swl367 commented 9 years ago

I understand we can add individual files to the target and add file references to those files, but can we do this in one step for an entire folder at some absolute path? (Of course there would need to be some way of knowing which files are .m files and which are .h)

e.g.

require 'xcodeproj' project_file = 'app.xcodeproj' project = Xcodeproj::Project.open(project_file)

kit_group = project.new_group('UIKIT') files = kit_group.new_files('absolute/path/to/my/files')

main_target = project.targets.first main_target.add_file_references([files])

project.save(project_file)

swl367 commented 9 years ago

nevermind, I got it working. for any one else that needs it:

require 'xcodeproj'

def addfiles (direc, current_group, main_target)
    Dir.glob(direc) do |item|
        next if item == '.' or item == '.DS_Store'

                if File.directory?(item)
            new_folder = File.basename(item)
            created_group = current_group.new_group(new_folder)
            addfiles("#{item}/*", created_group, main_target)
        else 
          i = current_group.new_file(item)
          if item.include? ".m"
              main_target.add_file_references([i])
          end
        end
    end
end

project_file = 'myproj' + '.xcodeproj'
project = Xcodeproj::Project.open(project_file)

kit_group = project.new_group('UIKIT')
data_group = project.new_group('DATAKIT')
ex_group = project.new_group('LIBKIT')

uipath = '/Git/UIKit'
datapath = '/Git/DataServicesKit'
expath = '/Git/External'

main_target = project.targets.first

addfiles("#{uipath}/*", kit_group, main_target)
addfiles("#{datapath}/*", data_group, main_target)
addfiles("#{expath}/*", ex_group, main_target)

project.save(project_file)
swl367 commented 9 years ago

is there a way to add something as a reference for the FacebookSDK framework? When I drag that framework, the headers folder is blue, but when I add it via new_file, then it's yellow and doesn't compile correctly

fabiopelosin commented 9 years ago

Please don't use the issues list for usage questions. You can find an example of how CocoaPods handles frameworks in its codebase.

briansoule commented 9 years ago

@fabiopelosin Could you provide a link to the .framework example?

fabiopelosin commented 9 years ago

https://github.com/CocoaPods/CocoaPods/blob/master/lib/cocoapods/installer/file_references_installer.rb#L82

revolter commented 6 years ago

The current link is: https://github.com/CocoaPods/CocoaPods/blob/377d9cdf4b542e7762fe833e01817a9e423edb34/lib/cocoapods/installer/xcode/pods_project_generator/file_references_installer.rb#L77-L85