Post

Replies

Boosts

Views

Activity

Device Activity Report: Resolving 'Context' Type Issue in TotalActivityReport.swift
Hello Apple Developers, I've encountered an issue while working on a DeviceActivityReport in Swift. The problem arises when attempting to use the Context type from DeviceActivityReport. Here is the snippet of the code causing the problem: import DeviceActivity import SwiftUI extension DeviceActivityReport.Context { // If your app initializes a DeviceActivityReport with this context, then the system will use // your extension's corresponding DeviceActivityReportScene to render the contents of the // report. static let totalActivity = Self("Total Activity") } struct TotalActivityReport: DeviceActivityReportScene { // Define which context your scene will represent. let context: DeviceActivityReport.Context = .totalActivity // Define the custom configuration and the resulting view for this report. let content: (String) -> TotalActivityView func makeConfiguration(representing data: DeviceActivityResults<DeviceActivityData>) async -> String { // Reformat the data into a configuration that can be used to create // the report's view. let formatter = DateComponentsFormatter() formatter.allowedUnits = [.day, .hour, .minute, .second] formatter.unitsStyle = .abbreviated formatter.zeroFormattingBehavior = .dropAll let totalActivityDuration = await data.flatMap { $0.activitySegments }.reduce(0, { $0 + $1.totalActivityDuration }) return formatter.string(from: totalActivityDuration) ?? "No activity data" } } Issue: The compiler throws the following errors: 'Context' is not a member type of struct 'DeviceActivityReport.DeviceActivityReport' 'Context' is not a member type of struct 'DeviceActivityReport.DeviceActivityReport' Possible Causes: There might be an issue with referencing DeviceActivityReport.Context directly. The correct type might be DeviceActivityReport.DeviceActivityReport.Context. These files were generated by Xcode, and nothing has been manually changed. Any insights or suggestions to resolve this issue would be greatly appreciated. Best regards,
1
1
407
Aug ’24