99import Foundation
1010
1111public protocol StreamWritable : class {
12- func write( _ string: String )
12+ func write( _ string: String ) throws
1313}
1414
1515public class ConsoleStreamWriter : StreamWritable {
@@ -80,41 +80,17 @@ struct Format {
8080 var indentation : Indentation = Indentation ( )
8181}
8282
83- struct PBXObjectType : Hashable , CustomStringConvertible {
84- let type : PBXObject . Type
85-
86- init ( type: PBXObject . Type ) {
87- self . type = type
88- }
89-
90- static func == ( lhs: PBXObjectType , rhs: PBXObjectType ) -> Bool {
91- return lhs. type == rhs. type
92- }
93-
94- var hashValue : Int {
95- return String ( describing: type) . hashValue
96- }
97-
98- var description : String {
99- return String ( describing: type)
100- }
101- }
102-
10383struct ObjectMap {
104- let objectMap : [ PBXObjectType : [ PBXObject ] ]
84+ let objectMap : [ String : [ PBXObject ] ]
10585
10686 init ( project: PBXProject ) {
107- var buckets : [ PBXObjectType : [ PBXObject ] ] = [ : ]
87+ var buckets : [ String : [ PBXObject ] ] = [ : ]
10888
10989 let visitor = ObjectVisitor ( )
11090 visitor. visit ( object: project)
11191
112- visitor. types. forEach {
113- buckets [ $0] = [ ]
114- }
115-
11692 visitor. allObjects. forEach { object in
117- buckets [ PBXObjectType ( type : type ( of: object) ) ] ! . append ( object)
93+ buckets [ String ( describing : type ( of: object) ) , default : [ ] ] . append ( object)
11894 }
11995
12096 self . objectMap = buckets
@@ -134,23 +110,23 @@ public final class PBXPListArchiver {
134110 archiveDictionary [ ProjectFile . RootKey. rootObject] = projectFile. project. plistID
135111 }
136112
137- public func write( stream: StreamWritable ) {
113+ public func write( stream: StreamWritable ) throws {
138114 var format = Format ( )
139115
140- stream. write ( " // !$*UTF8*$! \( format. endOfLine) " )
141- stream. write ( " { \( format. endOfLine) " )
116+ try stream. write ( " // !$*UTF8*$! \( format. endOfLine) " )
117+ try stream. write ( " { \( format. endOfLine) " )
142118 format. indentation. increase ( )
143- archiveDictionary. sorted { ( obj1, obj2) in
119+ try archiveDictionary. sorted { ( obj1, obj2) in
144120 return obj1. key < obj2. key
145121 } . forEach { ( key, value) in
146122 guard let value = value else { return }
147- stream. write ( " \( format. indentation) \( key) = " )
148- stream. write ( value. plistRepresentation ( format: format) )
149- stream. write ( " ; \( format. endOfLine) " )
123+ try stream. write ( " \( format. indentation) \( key) = " )
124+ try stream. write ( value. plistRepresentation ( format: format) )
125+ try stream. write ( " ; \( format. endOfLine) " )
150126 }
151127 format. indentation. decrease ( )
152128
153- stream. write ( " } \( format. endOfLine) " )
129+ try stream. write ( " } \( format. endOfLine) " )
154130 }
155131}
156132
@@ -168,21 +144,13 @@ final class ObjectVisitor {
168144 object. visit ( self )
169145 }
170146
171- var types : [ PBXObjectType ] {
172- return Array ( Set ( objectMap. map { PBXObjectType ( type: type ( of: $0. value) ) } ) )
173- }
174-
175147 var allObjects : [ PBXObject ] {
176148 return objects ( )
177149 }
178150
179151 func objects< T: PBXObject > ( ) -> [ T ] {
180152 return objectMap. flatMap { return $0. value as? T }
181153 }
182-
183- var keys : Set < PBXObject . ID > {
184- return Set ( objectMap. keys)
185- }
186154}
187155
188156extension PBXObject {
0 commit comments