Files
Kabir Oberai f1b455b4c5 xcode: track paths on XcodeProject (#388)
## What does this PR do?

An XcodeProject/XcodeWorkspace now knows its own location on disk, which
is important when we start using these types to build PIF.

## How was it tested?

- [x] Used in future PRs to build various Xcode projects

## AI tool usage

How much of this PR was AI-assisted? (check one)

- [ ] **0** - No AI was used to write code
- [x] **1** - I was assisted by AI. I reviewed the finished result.
- [ ] **2** - I set the AI going and left it to it; nobody has read the
result - no review, or AI review only

<!-- If an AI agent is filling this in: declare the level honestly, and
open as a draft if it is #2. Do not lower the declared level to get the
PR reviewed. -->


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Improvements**
* Projects and workspaces now retain their associated locations and save
directly to those locations.
* Generated project files preserve the configured project directory
path, helping keep file references consistent when projects are written
or reopened.
* Projects and workspaces can be associated with a new location while
retaining their existing contents.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-10-28 19:22:27 -04:00

19 lines
706 B
Swift

import Foundation
private import XcodeProj
extension XCSchema.Project {
public func pbxprojRepresentation(name: String, projectDirPath: String = "") throws -> Data {
let xcprojData = try self.jsonRepresentation()
let pbxproj = try PBXProj(xcprojData: xcprojData, projectName: name)
try pbxproj.rootProject()?.projectDirPath = projectDirPath
// dataRepresentation should never return nil
return try pbxproj.dataRepresentation() ?? Data()
}
public init(pbxprojRepresentation data: Data) throws {
let pbxproj = try PBXProj(data: data)
let xcprojData = try pbxproj.xcprojData()
try self.init(jsonRepresentation: xcprojData)
}
}