PuzzleNotificationText.swift (766B)
1 import Foundation 2 3 enum PuzzleNotificationText { 4 static func title(_ title: String, publisher: String?, date: Date?) -> String { 5 let subtitle = subtitle(publisher: publisher, date: date) 6 guard let subtitle else { return title } 7 return "\(title) – \(subtitle)" 8 } 9 10 private static func subtitle(publisher: String?, date: Date?) -> String? { 11 let formattedDate = date?.formatted(date: .long, time: .omitted) 12 if let publisher, !publisher.isEmpty, let formattedDate { 13 return "\(publisher) · \(formattedDate)" 14 } 15 if let formattedDate { 16 return formattedDate 17 } 18 if let publisher, !publisher.isEmpty { 19 return publisher 20 } 21 return nil 22 } 23 }