tweaked format of generated references

- more characters
- underscore after type name
- remove duplication count unless greater than 1
This commit is contained in:
Yonas Kolb
2017-11-15 10:11:58 +01:00
parent 5a74572e10
commit 034eb4a448
4 changed files with 463 additions and 463 deletions
+3 -2
View File
@@ -18,14 +18,15 @@ public class ReferenceGenerator {
public func generate<T: PBXObject>(_ element: T.Type, _ id: String) -> String {
var uuid: String = ""
var counter: UInt = 0
let characterCount = 16
let className: String = String(describing: T.self)
.replacingOccurrences(of: "PBX", with: "")
.replacingOccurrences(of: "XC", with: "")
let classAcronym = String(className.filter { String($0).lowercased() != String($0) })
let stringID = String(abs(id.hashValue).description.prefix(10 - classAcronym.count))
let stringID = String(abs(id.hashValue).description.prefix(characterCount - classAcronym.count - 2))
repeat {
uuid = "\(classAcronym)_\(stringID)\(counter > 0 ? "-\(counter)" : "")"
counter += 1
uuid = "\(classAcronym)\(stringID)\(String(format: "%02d", counter))"
} while (references.contains(uuid))
references.insert(uuid)
return uuid