[Swift] 35 Apple WatchのComplication改良 accessoryCorner

[M1 Mac, Ventura 13.3.1, Xcode 14.3]

ComplicationのaccessoryCornerにも日付を表示できるようにしました。

ただし現時点では文字盤に沿って円弧状に表示できるのはラベル[23/07/08(土)]だけで本体[令5]は水平のままです。

詳しくは書けませんが、次期watchOSで何らかの進化があるようです。

中央上部と右下に表示
struct ComplicationCorner : View {
    var entry: Provider.Entry
    
    var body: some View {
        Text(getFormattedYear())
        .font(.system(size: 22))
            .foregroundColor(.green)
            .widgetLabel {
                Text(getFormattedDate() + getFormattedWeekday())
                .foregroundColor(.yellow)
            }
     }
    
    func getFormattedDate() -> String {
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "yy/MM/dd"
        return dateFormatter.string(from: entry.date)
    }
    
    func getFormattedWeekday() -> String {
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "E"
        dateFormatter.locale = Locale(identifier: "ja_JP")
        return "(" + dateFormatter.string(from: entry.date) + ")"
    }
    
    func getFormattedYear() -> String {
        let calendar = Calendar(identifier: .japanese)
        let year = calendar.component(.year, from: entry.date)
        return "令" + String(year)
    }
    
}

struct DateToolComplicationEntryView : View {
    @Environment(\.widgetFamily) var widgetFamily
    var entry: Provider.Entry
    
    var body: some View {
        switch widgetFamily {
            case .accessoryCorner:
                ComplicationCorner(entry: entry)
            case .accessoryCircular:
                ComplicationCircular(entry: entry)
            case .accessoryInline:
                ComplicationInline()
            case .accessoryRectangular:
                ComplicationRectangular()
            @unknown default:
                Text("Not an implemented widget yet")
        }
    }
}