Skip to content
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

Create PBXProj from Data Representation #793

Closed
Ibrahimhass opened this issue Sep 1, 2023 · 1 comment
Closed

Create PBXProj from Data Representation #793

Ibrahimhass opened this issue Sep 1, 2023 · 1 comment

Comments

@Ibrahimhass
Copy link
Contributor

Ibrahimhass commented Sep 1, 2023

Context 🕵️‍♀️

We are working on a Server Side Swift application. We copy an archive containing a template Xcode project stored on disk to memory using ZipFoundation. We want to be able to re-create a PBXProj object from its data entry in the archive.

What 🌱

The project provides the following initializers for PBXProj

public init(rootObject: PBXProject? = nil,
    objectVersion: UInt = Xcode.LastKnown.objectVersion,
    archiveVersion: UInt = Xcode.LastKnown.archiveVersion,
    classes: [String: Any] = [:],
    objects: [PBXObject] = []) { ... }

public convenience init(path: Path) throws { ... }

Proposal 🎉

We can have a simple initializer that can create a PBXProj from the project data.

public convenience init(data: Data) throws {
    var propertyListFormat = PropertyListSerialization.PropertyListFormat.xml

    let serialized = try PropertyListSerialization.propertyList(
        from: data,
        options: .mutableContainersAndLeaves,
        format: &propertyListFormat
    )

    // swiftlint:disable:next force_cast
    let pbxProjDictionary = serialized as! [String: Any]
        
    let context = ProjectDecodingContext(
        pbxProjValueReader: { key in
            pbxProjDictionary[key]
        }
    )

    let plistDecoder = XcodeprojPropertyListDecoder(context: context)
    let pbxproj: PBXProj = try plistDecoder.decode(PBXProj.self, from: data)

    self.init(
        rootObject: pbxproj.rootObject,
        objectVersion: pbxproj.objectVersion,
        archiveVersion: pbxproj.archiveVersion,
        classes: pbxproj.classes,
        objects: pbxproj.objects
    )
}
@github-actions
Copy link

github-actions bot commented Oct 7, 2023

Hola 👋,

We want to inform you that the issue has been marked as stale. This means that there hasn't been any activity or updates on it for quite some time, and it's possible that it may no longer be relevant or actionable.
If you still believe that this issue is valid and requires attention, please provide an update or any additional information that can help us address it. Otherwise, we may consider closing it in the near future.
Thank you for your understanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant