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 class from the Data reprentation of a pbxproj file #798

Merged
merged 5 commits into from
Oct 12, 2023

Conversation

Ibrahimhass
Copy link
Contributor

#793

Short description 📝

This change adds a convenience initializer to PBXProj so that it can be initialized from the data representation of a pbxproj file.
The current APIs can create a PBXProj class when the path to a pbxproj file is provided.
I want to initialize the PBXProj file from the data representation of a pbxproj stored inside an in-memory archive.
This is needed because we are making a server-side Swift application and want to minimize disk operations.

Solution 📦

Added a convenience initializer to PBXProj extension that we can create a PBXProj instance using the data representation of a pbxproj file.

Implementation 👩‍💻👨‍💻

/// Initializes the project with the data representation of pbxproj file.
///
/// - Parameters:
///   - data: data representation of pbxproj file.
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
    )
}

@netlify
Copy link

netlify bot commented Sep 12, 2023

Deploy Preview for xcodeproj ready!

Name Link
🔨 Latest commit c014db6
🔍 Latest deploy log https://app.netlify.com/sites/xcodeproj/deploys/65239fe3ab50380008ecdf29
😎 Deploy Preview https://deploy-preview-798--xcodeproj.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Collaborator

@kwridan kwridan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Ibrahimhass

Tests/XcodeProjTests/Project/XcodeProjTests.swift Outdated Show resolved Hide resolved
Copy link
Collaborator

@kwridan kwridan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Ibrahimhass

For your use case did you run into issues with name being omitted / missing? would that require some additional follow up?

@Ibrahimhass
Copy link
Contributor Author

@kwridan For my use case, name does not matter. I am using the forked version for development right now.

@kwridan kwridan merged commit c3f69fc into tuist:main Oct 12, 2023
9 checks passed
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

Successfully merging this pull request may close these issues.

None yet

4 participants