New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Creating a PBXGroup #43
Comments
@Daltron you need to change pbxproj.objects.append(.pbxGroup(newGroup)) |
@filletofish Thanks for replying. That adds it to the objects group but it doesn't show up in the actual xcodeproj when I write it back to the disk. Here is how I am creating my group: let project = try! XcodeProj(path: "testing.xcodeproj")
var pbxproj = project.pbxproj
var group = PBXGroup(reference: pbxproj.generateUUID(for: PBXGroup.self), // This doesn't seem right?
children: [],
sourceTree: pbxproj.objects.groups[2].sourceTree)
group.name = "CustomPBXGroup"
pbxproj.objects.append(.pbxGroup(group))
try! project.write(path: "testing.xcodeproj", override: true) Am I doing something wrong here? |
@Daltron I have never tried it so. @pepibumur should now :) |
Hey @Daltron let project = try! XcodeProj(path: "testing.xcodeproj")
var group = PBXGroup(reference: pbxproj.generateUUID(for: PBXGroup.self), // This doesn't seem right?
children: [],
sourceTree: pbxproj.objects.groups[2].sourceTree)
group.name = "CustomPBXGroup"
project.pbxproj.objects.append(.pbxGroup(group))
try! project.write(path: "testing.xcodeproj", override: true) Notice that I don't create a new variable Could you try and let me know if that works? |
Yeah, there's a rational for changing at least some of the top level structs to classes, to make things easier to update |
@pepibumur That seems to add it to my xcodeproj when I look at the raw text, but what if I am wanting to add that group to a group that already exists in my xcodeproj? I've tried project.pbxproj.objects.groups[2].children.append(group.reference) but since groups is a read only property, this won't work. |
Good point @Daltron. What do you think about building an interface method like this one? var myObject = project.pbxproj.objects.groups[2]
myObject.children.append(group.reference)
project.pbxproj.update(object: myObject) Since objects include a reference we can find the object in the array and update it. What do you think? cc @yonaskolb |
I think all the different object types should be mutable arrays on the project, instead of having them be getters on the This would also speed up the writing of a project a lot as those object type getters (for example |
Good point, thinking about it, I think makes sense since we need to filter them later on when we export the project. Is there any advantage in having them as a single array? |
The only advantage I can see is that the project properties used to be immutable so the only way to edit these was to use the initialiser which would have been crazy with a dozen different array. But now that things are mutable, they can be changed after the fact. The init param could be left as an optional though. The object property could also still be used as a getter. I know its used for checking all the references for the reference generator, but this could be typed to a project element array. Hope that makes sense :) |
Having said that, it makes it easier to add objects but doesn't really solve the problem of editing them. The fact is that Structs in an array are hard to edit as you have to pull them out, edit them and then update the array. This would all be easier if they were classes. Would would be the biggest downside of having the project elements be classes? |
The more I think about it the more I think it'd make sense to move everything into classes. Thinking about the project as a tree of immutable elements I think it'd be much easier if those elements were just classes and you could modify the tree at any point that you want. We'd simplify the APIs a lot. |
What do you think @yonaskolb ? |
Agreed 👍 |
I've created an issue to tackle the migration to classes. You can follow it up here #45 |
@Daltron, now with release 0.1.0 you can add your group as follows:
|
@yonaskolb Thanks for the prompt response! Looking forward to trying this out! |
Is it possible to create a new
PBXGroup
and append it to the Xcode project?I've tried this:
but
groups
is read only property.Is there a way to do this?
The text was updated successfully, but these errors were encountered: