Skip to content

Commit 16a8a14

Browse files
committed
♻️ Make default object
1 parent 42c1c98 commit 16a8a14

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

Sources/Model/Title.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ struct Legend: Codable, Equatable {
1919
lhs.description == rhs.description &&
2020
lhs.icon == rhs.icon
2121
}
22+
23+
static let Empty = Legend(description: "", icon: "")
2224
}
2325

2426
extension Character {
@@ -38,20 +40,15 @@ extension Character {
3840

3941
extension String {
4042
func asLegend() -> Legend {
41-
let chars = Array(self)
42-
43-
guard let firstChar = chars.first else {
44-
return Legend(description: "", icon: "")
43+
guard let firstChar = first else {
44+
return Legend.Empty
4545
}
4646

47-
var description = self
48-
var icon = ""
49-
5047
if firstChar.isEmoji {
51-
description = String(chars.dropFirst()).trimmingCharacters(in: .whitespacesAndNewlines)
52-
icon = String(firstChar)
48+
let description = String(dropFirst()).trimmingCharacters(in: .whitespacesAndNewlines)
49+
return Legend(description: description, icon: String(firstChar))
5350
}
5451

55-
return Legend(description: description, icon: icon)
52+
return Legend(description: self, icon: "")
5653
}
5754
}

0 commit comments

Comments
 (0)