@@ -39,26 +39,15 @@ public final class ProjectFile {
3939 public private( set) var project : PBXProject
4040
4141 let url : URL
42- let fileWrapper : FileWrapper
4342
4443 /// Initializes a new project file from the given URL
4544 ///
4645 /// - Parameter url: Path to an xcodeproj file to be opened
4746 /// - Returns: A fully parsed project from the provided source or `nil` if an error happened
4847 public init ( url: URL ) throws {
4948 self . url = url
50- self . fileWrapper = try FileWrapper ( url: url, options: [ ] )
51- guard fileWrapper. isDirectory else {
52- throw CocoaError . error ( . fileReadUnknown)
53- }
54-
55- guard let pbxproj = fileWrapper. fileWrappers ? [ " project.pbxproj " ] , pbxproj. isRegularFile else {
56- throw CocoaError . error ( . fileReadUnknown)
57- }
58-
59- guard let data = pbxproj. regularFileContents else {
60- throw Error . invalid
61- }
49+ let pbxproj = URL ( fileURLWithPath: " project.pbxproj " , relativeTo: url)
50+ let data = try Data ( contentsOf: pbxproj)
6251
6352 guard let plist = try PropertyListSerialization . propertyList ( from: data, options: [ ] , format: nil ) as? [ String : Any ] else {
6453 throw Error . invalidPlist
@@ -85,23 +74,6 @@ public final class ProjectFile {
8574 project. path = url. path
8675 self . project = project
8776 }
88-
89- public func currentFileWrapper( ) throws -> FileWrapper {
90- let currentFileWrapper = fileWrapper
91-
92- let oldPbxproj = currentFileWrapper. fileWrappers![ " project.pbxproj " ] !
93-
94- let dataStream = DataStreamWriter ( )
95- let archiver = PBXPListArchiver ( projectFile: self )
96- try archiver. write ( stream: dataStream)
97- let newPbxproj = FileWrapper ( regularFileWithContents: dataStream. data)
98- newPbxproj. preferredFilename = " project.pbxproj "
99-
100- currentFileWrapper. removeFileWrapper ( oldPbxproj)
101- currentFileWrapper. addFileWrapper ( newPbxproj)
102-
103- return currentFileWrapper
104- }
10577}
10678
10779extension ProjectFile {
@@ -112,19 +84,10 @@ extension ProjectFile {
11284 public func save( to destination: URL ? = nil ) throws {
11385 let destination = destination ?? url
11486
115- guard let oldPbxproj = fileWrapper. fileWrappers ? [ " project.pbxproj " ] , oldPbxproj. isRegularFile else {
116- throw CocoaError . error ( . fileReadUnknown)
117- }
118-
11987 let dataStream = DataStreamWriter ( )
12088 let archiver = PBXPListArchiver ( projectFile: self )
12189 try archiver. write ( stream: dataStream)
122- let newPbxproj = FileWrapper ( regularFileWithContents: dataStream. data)
123- newPbxproj. preferredFilename = " project.pbxproj "
124-
125- fileWrapper. removeFileWrapper ( oldPbxproj)
126- fileWrapper. addFileWrapper ( newPbxproj)
127-
128- try fileWrapper. write ( to: destination, options: [ . atomic] , originalContentsURL: nil )
90+ let pbxprojURL = URL ( fileURLWithPath: " project.pbxproj " , relativeTo: destination)
91+ try dataStream. data. write ( to: pbxprojURL, options: [ . atomic] )
12992 }
13093}
0 commit comments