diff --git a/CHANGELOG.md b/CHANGELOG.md index 378cd39b2..b0255426b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ ## Master ##### Enhancements +* Support On-Demand Resource + [JunyiXie](https://github.com/JunyiXie) + [#issue_number](https://github.com/CocoaPods/Xcodeproj/pull/742) * Add new APIs to set testables or entries in schemes. [Dimitris Koutsogiorgas](https://github.com/dnkoutso) diff --git a/lib/xcodeproj/project/object/native_target.rb b/lib/xcodeproj/project/object/native_target.rb index b9d36641f..568f87259 100644 --- a/lib/xcodeproj/project/object/native_target.rb +++ b/lib/xcodeproj/project/object/native_target.rb @@ -552,6 +552,40 @@ def add_resources(resource_file_references) end end + # Remove on demand resource to the resources build phase of the target. + # + # @param {String => [Array]} on_demand_resource_tag_files + # the files references of the on demand resources to the target. + # + # @return [void] + # + def remove_on_demand_resources(on_demand_resource_tag_files) + on_demand_resource_tag_files.each do |_, files| + files.each do |file| + resources_build_phase.remove_file_reference(file) + end + end + end + + # Adds on demand resource to the resources build phase of the target. + # + # @param {String => [Array]} on_demand_resource_tag_files + # the files references of the on demand resource to the target. + # + # @return [void] + # + def add_on_demand_resources(on_demand_resource_tag_files) + on_demand_resource_tag_files.each do |tag_name, files| + files.each do |file| + next if resources_build_phase.include?(file) + build_file = project.new(PBXBuildFile) + build_file.file_ref = file + build_file.settings = (build_file.settings ||= {}).merge('ASSET_TAGS' => [tag_name]) + resources_build_phase.files << build_file + end + end + end + # Finds or creates the headers build phase of the target. # # @note A target should have only one headers build phase.