I'm trying to populate DeviceActivityReportScene from DeviceActivityData. I have a list of custom objects of type 'DailyLimit' and I want to create separate instances of 'DeviceActivityReportScene' for each item inside the array.
The following code works. This creates two separate instances of DeviceActivityReportScene for the item 0 and item 1 in the array.
@main
struct ReportingExtension: DeviceActivityReportExtension {
let limits = Store.shared.getDailyLimits()
var body: some DeviceActivityReportScene {
DailyLimitActivityReport(dailyLimit: limits[0], context: DeviceActivityReport.Context(rawValue: limits[0].id)) { report in
DailyLimitActivityView(activityReport: report)
}
DailyLimitActivityReport(dailyLimit: limits[1], context: DeviceActivityReport.Context(rawValue: limits[1].id)) { report in
DailyLimitActivityView(activityReport: report)
}
}
}
struct DailyLimitActivityReport: DeviceActivityReportScene {
let dailyLimit: DailyLimit
let context: DeviceActivityReport.Context
let content: (ActivityReport) -> DailyLimitActivityView
func makeConfiguration(representing data: DeviceActivityResults<DeviceActivityData>) async -> ActivityReport {
...
}
}
But I want to create the list of DeviceActivityReportScene dynamically like the following.
@main
struct ReportingExtension: DeviceActivityReportExtension {
let limits = Store.shared.getDailyLimits()
var body: some DeviceActivityReportScene {
ForEach(limits) {
limit in
DailyLimitActivityReport(dailyLimit: limit, context: DeviceActivityReport.Context(rawValue: limit.id)) { report in
DailyLimitActivityView(activityReport: report)
}
}
}
}
But this throws an error 'No exact matches in reference to static method 'buildExpression'
Any ideas to fix this issue will be highly appreciated & thanks in advance.