Skip to content

Commit 4815194

Browse files
committed
Refactored CENotification to use delegated inits.
1 parent dc33a4e commit 4815194

File tree

1 file changed

+43
-19
lines changed

1 file changed

+43
-19
lines changed

CodeEdit/Features/Notifications/Models/CENotification.swift

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,16 @@ struct CENotification: Identifiable, Equatable {
3737
isSticky: Bool = false,
3838
isRead: Bool = false
3939
) {
40-
self.id = id
41-
self.icon = .symbol(name: iconSymbol, color: iconColor)
42-
self.title = title
43-
self.description = description
44-
self.actionButtonTitle = actionButtonTitle
45-
self.action = action
46-
self.isSticky = isSticky
47-
self.isRead = isRead
48-
self.timestamp = Date()
40+
self.init(
41+
id: id,
42+
icon: .symbol(name: iconSymbol, color: iconColor),
43+
title: title,
44+
description: description,
45+
actionButtonTitle: actionButtonTitle,
46+
action: action,
47+
isSticky: isSticky,
48+
isRead: isRead
49+
)
4950
}
5051

5152
init(
@@ -60,15 +61,16 @@ struct CENotification: Identifiable, Equatable {
6061
isSticky: Bool = false,
6162
isRead: Bool = false
6263
) {
63-
self.id = id
64-
self.icon = .text(iconText, backgroundColor: iconColor, textColor: iconTextColor)
65-
self.title = title
66-
self.description = description
67-
self.actionButtonTitle = actionButtonTitle
68-
self.action = action
69-
self.isSticky = isSticky
70-
self.isRead = isRead
71-
self.timestamp = Date()
64+
self.init(
65+
id: id,
66+
icon: .text(iconText, backgroundColor: iconColor, textColor: iconTextColor),
67+
title: title,
68+
description: description,
69+
actionButtonTitle: actionButtonTitle,
70+
action: action,
71+
isSticky: isSticky,
72+
isRead: isRead
73+
)
7274
}
7375

7476
init(
@@ -80,9 +82,31 @@ struct CENotification: Identifiable, Equatable {
8082
action: @escaping () -> Void,
8183
isSticky: Bool = false,
8284
isRead: Bool = false
85+
) {
86+
self.init(
87+
id: id,
88+
icon: .image(iconImage),
89+
title: title,
90+
description: description,
91+
actionButtonTitle: actionButtonTitle,
92+
action: action,
93+
isSticky: isSticky,
94+
isRead: isRead
95+
)
96+
}
97+
98+
private init(
99+
id: UUID,
100+
icon: IconType,
101+
title: String,
102+
description: String,
103+
actionButtonTitle: String,
104+
action: @escaping () -> Void,
105+
isSticky: Bool,
106+
isRead: Bool
83107
) {
84108
self.id = id
85-
self.icon = .image(iconImage)
109+
self.icon = icon
86110
self.title = title
87111
self.description = description
88112
self.actionButtonTitle = actionButtonTitle

0 commit comments

Comments
 (0)