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

Add an option to get the String representation of PBXProj #786

Closed
Ibrahimhass opened this issue Jul 31, 2023 · 0 comments · Fixed by #787
Closed

Add an option to get the String representation of PBXProj #786

Ibrahimhass opened this issue Jul 31, 2023 · 0 comments · Fixed by #787

Comments

@Ibrahimhass
Copy link
Contributor

Ibrahimhass commented Jul 31, 2023

Context 🕵️‍♀️

I want to modify a pbxproj in memory to later add it to an in-memory archive.
This is needed because we are making a server-side Swift application.
Since it is a server-side application, it would be great to get the modified pbxproj without any extra disk I/O operations.
The current APIs cannot achieve this without first writing the pbxproj to disk.

What 🌱

The project generates a String representation of the pbxproj internally before saving to disk.
Below is the relevant code block inside PBXProj.swift.

extension PBXProj: Writable {
    public func write(path: Path, override: Bool) throws {
        try write(path: path, override: override, outputSettings: PBXOutputSettings())
    }

    public func write(path: Path, override: Bool, outputSettings: PBXOutputSettings) throws {
        let encoder = PBXProjEncoder(outputSettings: outputSettings)
        let output = try encoder.encode(proj: self)
        if override, path.exists {
            try path.delete()
        }
        try path.write(output)
    }
}

Proposal 🎉

With the following simple refactor, this can be achieved with ease.

extension PBXProj: Writable {
    public func write(path: Path, override: Bool) throws {
        try write(path: path, override: override, outputSettings: PBXOutputSettings())
    }

    public func write(path: Path, override: Bool, outputSettings: PBXOutputSettings) throws {
        let output = try encodeAsString(outputSettings: outputSettings)
        if override, path.exists {
            try path.delete()
        }
        try path.write(output)
    }
    
    public func encodeAsString(outputSettings: PBXOutputSettings) throws -> String {
        let encoder = PBXProjEncoder(outputSettings: outputSettings)
        return try encoder.encode(proj: self)
    }
}
@Ibrahimhass Ibrahimhass changed the title Add an option to get the String representation of PBXProj. Add an option to get the String representation of PBXProj Jul 31, 2023
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 a pull request may close this issue.

1 participant