如何在Xcode中使用#Preview宏

问题描述 投票:0回答:1

如何将此代码重构到 Xcode 15 并使预览正常工作?

struct HistoryView_Previews: PreviewProvider {
    static var history: History {
        History(attendees: [
            DailyScrum.Attendee(name: "Jon"),
            DailyScrum.Attendee(name: "Darla"),
            DailyScrum.Attendee(name: "Luis")
        ],
                transcript: "Darla, would you like to start today? Sure, yesterday I reviewed Luis' PR and met with the design team to finalize the UI...")
    }
    
    static var previews: some View {
        HistoryView(history: history)
    }
}

我不知道如何使用这个新的#Preview,求助!

ios swift xcode swiftui preview
1个回答
0
投票

您可以像这样转换为#Preview宏样式:

#Preview {
    var history: History {
        History(attendees: [
            DailyScrum.Attendee(name: "Jon"),
            DailyScrum.Attendee(name: "Darla"),
            DailyScrum.Attendee(name: "Luis")
        ],
                transcript: "Darla, would you like to start today? Sure, yesterday I reviewed Luis' PR and met with the design team to finalize the UI...")
    }

    return HistoryView(history: history)
}
© www.soinside.com 2019 - 2024. All rights reserved.