Skip to content

Commit 1fdc6f7

Browse files
committed
init throws serialization errors
1 parent 22d251c commit 1fdc6f7

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

Example/Example/main.swift

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,8 @@ import Foundation
1212
let projectFile = "project.pbxproj"
1313

1414

15-
// Call plutil to convert pbxproj file to JSON
16-
let task = NSTask()
17-
task.launchPath = "/usr/bin/plutil"
18-
task.arguments = ["-convert", "json", "-o", "-", projectFile]
19-
20-
let pipe = NSPipe()
21-
task.standardOutput = pipe
22-
task.launch()
23-
24-
let data = pipe.fileHandleForReading.readDataToEndOfFile()
25-
let output = NSString(data: data, encoding: NSUTF8StringEncoding) as! String
26-
27-
2815
// Parse JSON to XCProjectFile object
29-
let proj = XCProjectFile(filename: "project.pbxproj")!
16+
let proj = try! XCProjectFile(filename: projectFile)!
3017

3118
// Print paths for all files in Resources build phases
3219
for target in proj.project.targets {

Xcode/Xcode/XCProjectFile.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,18 @@ public class XCProjectFile {
4646
let openStepFormat: Bool
4747
let allObjects = AllObjects()
4848

49-
public convenience init?(filename: String) {
49+
public convenience init?(filename: String) throws {
5050

5151
guard let data = NSData(contentsOfFile: filename) else { return nil }
5252

53+
try self.init(propertyListData: data)
54+
}
55+
56+
public convenience init?(propertyListData data: NSData) throws {
57+
5358
let options = NSPropertyListReadOptions.Immutable
5459
var format: NSPropertyListFormat = NSPropertyListFormat.BinaryFormat_v1_0
55-
let obj = try? NSPropertyListSerialization.propertyListWithData(data, options: options, format: &format)
60+
let obj = try NSPropertyListSerialization.propertyListWithData(data, options: options, format: &format)
5661

5762
guard let dict = obj as? JsonObject else { return nil }
5863

@@ -181,7 +186,6 @@ public class PBXGroup : PBXReference {
181186
// convenience accessors
182187
public lazy var subGroups: [PBXGroup] = self.children.ofType(PBXGroup.self)
183188
public lazy var fileRefs: [PBXFileReference] = self.children.ofType(PBXFileReference)
184-
185189
}
186190

187191
public class PBXVariantGroup : PBXGroup {

0 commit comments

Comments
 (0)