How to add xcdatamodeld to project correctly? #21

Closed
yury opened this Issue Jul 12, 2012 · 8 comments

2 participants

@yury

Can't figure out how to correctly add xcdatamodeld to project.

project = Xcodeproj::Project.new
resources = project.groups.new('path' => resources_path, 'name' => 'Resources')
resources.files.new('path' => path_to_xcdatamodeld)
project.save_as("ui.xcodeproj")

if I open ui.xcodeproj then I can't open added xcdatamodeld %( Any hint to get it working?

@alloy
CocoaPods member

I think the best way to debug this is by creating an Xcode project manually and then compare that with the result of your code snippet.

@yury yury closed this Jul 13, 2012
@alloy
CocoaPods member

I would love a patch for this :) Is that something you were planning to do?

@alloy alloy reopened this Jul 13, 2012
@yury

Would like create patch but I'm afraid that I don't understand xcode structure and this project completely.

Should it be custom group class?
What interface you would like to see?

@alloy
CocoaPods member

If I understood your example correctly, it is a specialized version of a PBXGroup, right? So I think you really only need to add a XCVersionGroup subclass of PBXGroup, which can be done in the existing group source file and a little doc that explains what this type of group is used for.

@alloy
CocoaPods member

A version_groups method on PBXGroup might be handy. It would cleanup your code to:

resources.version_groups.new('path' => file, 'versionGroupType' => 'wrapper.xcdatamodel')

And since there apparently can be multiple wrapper types, a factory class method like this:

class XCVersionGroup < PBXGroup
  def self.new_xcmodeldata_group(project, xcmodeldata_path)
    group = new(project, nil, 'versionGroupType' => 'wrapper.xcdatamodel')
    file = group.files.new('path' => file.gsub(/xcdatamodeld$/, 'xcdatamodel'), 'sourceTree' => '<group>', 'lastKnownFileType' => 'wrapper.xcdatamodel')
    group.currentVersion = file.uuid
    group
  end
end

Which would reduce your code to:

resources.version_groups.new_xcmodeldata_group(file)
@yury

thanks, will try to provide patch later today

@alloy
CocoaPods member

Sweet, thanks :)

@alloy alloy closed this in 0feeb18 Jul 13, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment