Skip to content

Commit 8c0a184

Browse files
committed
Deduplicate known asset tags
1 parent 30bf623 commit 8c0a184

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Sources/RswiftGenerators/XcodeProject+Generator.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,23 @@ import Foundation
1010
public struct XcodeProjectGenerator {
1111
public static func generateProject(developmentRegion: String?, knownAssetTags: [String]?) -> Struct {
1212
Struct(name: SwiftIdentifier(name: "project")) {
13+
let warning: (String) -> Void = { print("warning: [R.swift]", $0) }
14+
1315
if let developmentRegion {
1416
LetBinding(name: SwiftIdentifier(name: "developmentRegion"), valueCodeString: #""\#(developmentRegion)""#)
1517
}
1618

1719
if let knownAssetTags {
18-
Struct(name: SwiftIdentifier(name: "knownAssetTags"), protocols: [.sequence]) {
19-
knownAssetTags.map { tag in
20-
LetBinding(name: SwiftIdentifier(name: tag), valueCodeString: #""\#(tag)""#)
21-
}
20+
let grouped = knownAssetTags.grouped(bySwiftIdentifier: { $0 })
21+
grouped.reportWarningsForDuplicatesAndEmpties(source: "known asset tag", result: "known asset tag", warning: warning)
22+
if grouped.uniques.count > 0 {
23+
Struct(name: SwiftIdentifier(name: "knownAssetTags"), protocols: [.sequence]) {
24+
grouped.uniques.map { tag in
25+
LetBinding(name: SwiftIdentifier(name: tag), valueCodeString: #""\#(tag)""#)
26+
}
2227

23-
generateMakeIterator(names: knownAssetTags.map { SwiftIdentifier(name: $0) })
28+
generateMakeIterator(names: grouped.uniques.map { SwiftIdentifier(name: $0) })
29+
}
2430
}
2531
}
2632
}

0 commit comments

Comments
 (0)