@@ -25,24 +25,36 @@ enum ProjectFileError : ErrorType, CustomStringConvertible {
25
25
}
26
26
}
27
27
28
+ public class AllObjects {
29
+ var dict : [ String : PBXObject ] = [ : ]
30
+ var fullFilePaths : [ String : String ] = [ : ]
31
+
32
+ func object< T : PBXObject > ( key: String ) -> T {
33
+ let obj = dict [ key] !
34
+ if let t = obj as? T {
35
+ return t
36
+ }
37
+
38
+ return T ( id: key, dict: obj. dict, allObjects: self )
39
+ }
40
+ }
41
+
28
42
public class XCProjectFile {
29
43
public let project : PBXProject
30
44
let dict : JsonObject
31
45
let format : NSPropertyListFormat
32
- let allObjects : AllObjects
46
+ let allObjects = AllObjects ( )
33
47
34
48
public convenience init ( xcodeprojPath: String ) throws {
35
49
36
50
guard let data = NSData ( contentsOfFile: xcodeprojPath + " /project.pbxproj " ) else {
37
51
throw ProjectFileError . MissingPbxproj
38
52
}
39
53
40
- let name = try XCProjectFile . projectName ( xcodeprojPath)
41
-
42
- try self . init ( propertyListData: data, projectName: name)
54
+ try self . init ( propertyListData: data)
43
55
}
44
56
45
- public convenience init ( propertyListData data: NSData , projectName : String ) throws {
57
+ public convenience init ( propertyListData data: NSData ) throws {
46
58
47
59
let options = NSPropertyListReadOptions . Immutable
48
60
var format : NSPropertyListFormat = NSPropertyListFormat . BinaryFormat_v1_0
@@ -52,13 +64,12 @@ public class XCProjectFile {
52
64
throw ProjectFileError . InvalidData
53
65
}
54
66
55
- self . init ( dict: dict, format: format, projectName : projectName )
67
+ self . init ( dict: dict, format: format)
56
68
}
57
69
58
- init ( dict: JsonObject , format: NSPropertyListFormat , projectName : String ) {
70
+ init ( dict: JsonObject , format: NSPropertyListFormat ) {
59
71
self . dict = dict
60
72
self . format = format
61
- self . allObjects = AllObjects ( projectName: projectName)
62
73
let objects = dict [ " objects " ] as! [ String : JsonObject ]
63
74
64
75
for (key, obj) in objects {
@@ -88,65 +99,9 @@ public class XCProjectFile {
88
99
static func createObject( id: String , dict: JsonObject , allObjects: AllObjects ) -> PBXObject {
89
100
let isa = dict [ " isa " ] as? String
90
101
91
- if isa == " PBXProject " {
92
- return PBXProject ( id: id, dict: dict, allObjects: allObjects)
93
- }
94
- if isa == " PBXContainerItemProxy " {
95
- return PBXContainerItemProxy ( id: id, dict: dict, allObjects: allObjects)
96
- }
97
- if isa == " PBXBuildFile " {
98
- return PBXBuildFile ( id: id, dict: dict, allObjects: allObjects)
99
- }
100
- if isa == " PBXCopyFilesBuildPhase " {
101
- return PBXCopyFilesBuildPhase ( id: id, dict: dict, allObjects: allObjects)
102
- }
103
- if isa == " PBXFrameworksBuildPhase " {
104
- return PBXFrameworksBuildPhase ( id: id, dict: dict, allObjects: allObjects)
105
- }
106
- if isa == " PBXHeadersBuildPhase " {
107
- return PBXHeadersBuildPhase ( id: id, dict: dict, allObjects: allObjects)
108
- }
109
- if isa == " PBXResourcesBuildPhase " {
110
- return PBXResourcesBuildPhase ( id: id, dict: dict, allObjects: allObjects)
111
- }
112
- if isa == " PBXShellScriptBuildPhase " {
113
- return PBXShellScriptBuildPhase ( id: id, dict: dict, allObjects: allObjects)
114
- }
115
- if isa == " PBXSourcesBuildPhase " {
116
- return PBXSourcesBuildPhase ( id: id, dict: dict, allObjects: allObjects)
117
- }
118
- if isa == " PBXBuildStyle " {
119
- return PBXBuildStyle ( id: id, dict: dict, allObjects: allObjects)
120
- }
121
- if isa == " XCBuildConfiguration " {
122
- return XCBuildConfiguration ( id: id, dict: dict, allObjects: allObjects)
123
- }
124
- if isa == " PBXAggregateTarget " {
125
- return PBXAggregateTarget ( id: id, dict: dict, allObjects: allObjects)
126
- }
127
- if isa == " PBXNativeTarget " {
128
- return PBXNativeTarget ( id: id, dict: dict, allObjects: allObjects)
129
- }
130
- if isa == " PBXTargetDependency " {
131
- return PBXTargetDependency ( id: id, dict: dict, allObjects: allObjects)
132
- }
133
- if isa == " XCConfigurationList " {
134
- return XCConfigurationList ( id: id, dict: dict, allObjects: allObjects)
135
- }
136
- if isa == " PBXReference " {
137
- return PBXReference ( id: id, dict: dict, allObjects: allObjects)
138
- }
139
- if isa == " PBXFileReference " {
140
- return PBXFileReference ( id: id, dict: dict, allObjects: allObjects)
141
- }
142
- if isa == " PBXGroup " {
143
- return PBXGroup ( id: id, dict: dict, allObjects: allObjects)
144
- }
145
- if isa == " PBXVariantGroup " {
146
- return PBXVariantGroup ( id: id, dict: dict, allObjects: allObjects)
147
- }
148
- if isa == " XCVersionGroup " {
149
- return XCVersionGroup ( id: id, dict: dict, allObjects: allObjects)
102
+ if let isa = isa,
103
+ let type = types [ isa] {
104
+ return type. init ( id: id, dict: dict, allObjects: allObjects)
150
105
}
151
106
152
107
// Fallback
@@ -173,3 +128,26 @@ public class XCProjectFile {
173
128
return ps
174
129
}
175
130
}
131
+
132
+ let types : [ String : PBXObject . Type ] = [
133
+ " PBXProject " : PBXProject . self,
134
+ " PBXContainerItemProxy " : PBXContainerItemProxy . self,
135
+ " PBXBuildFile " : PBXBuildFile . self,
136
+ " PBXCopyFilesBuildPhase " : PBXCopyFilesBuildPhase . self,
137
+ " PBXFrameworksBuildPhase " : PBXFrameworksBuildPhase . self,
138
+ " PBXHeadersBuildPhase " : PBXHeadersBuildPhase . self,
139
+ " PBXResourcesBuildPhase " : PBXResourcesBuildPhase . self,
140
+ " PBXShellScriptBuildPhase " : PBXShellScriptBuildPhase . self,
141
+ " PBXSourcesBuildPhase " : PBXSourcesBuildPhase . self,
142
+ " PBXBuildStyle " : PBXBuildStyle . self,
143
+ " XCBuildConfiguration " : XCBuildConfiguration . self,
144
+ " PBXAggregateTarget " : PBXAggregateTarget . self,
145
+ " PBXNativeTarget " : PBXNativeTarget . self,
146
+ " PBXTargetDependency " : PBXTargetDependency . self,
147
+ " XCConfigurationList " : XCConfigurationList . self,
148
+ " PBXReference " : PBXReference . self,
149
+ " PBXFileReference " : PBXFileReference . self,
150
+ " PBXGroup " : PBXGroup . self,
151
+ " PBXVariantGroup " : PBXVariantGroup . self,
152
+ " XCVersionGroup " : XCVersionGroup . self
153
+ ]
0 commit comments