CocoaPods / Xcodeproj

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

What's the best way to create a structure of nested groups? #931

Open wojciech-kulik opened 5 months ago

wojciech-kulik commented 5 months ago

Let's assume that I'm in a group A. Now I want to create a structure:

A
-- B
---- C

Is there any function that makes this task easy? Or do I have to split the path and go group by group and create it?

That's what I managed to achieve so far:

def add_group(project, group_path)
  splitted_path = group_path.split("/")

  for i in 1..(splitted_path.length - 2)
    current_path = splitted_path[0..i].join("/")
    new_group_path = current_path + "/" + splitted_path[i + 1]
    parent_group = find_group_by_absolute_dir_path(project, current_path)

    parent_group.new_group(splitted_path[i + 1], new_group_path) unless parent_group.nil?
  end

  project.save
end