Does ReportKit support SwiftData?
Yes, classes used in SwiftData are supported. However in order for ReportKit to access the properties of your SwiftData classes, they must conform to the CustomReflectable protocol. Below is an example class that conforms to this protocol. This is only required for classes that do not inherit from NSObject.
- import SwiftUI
- import SwiftData
- @Model
- class Book: CustomReflectable {
- var title: String
- var author: String
- var dateRead: Date
- var rating: Int?
- var status: Status
-
- init(
- title: String,
- author: String,
- dateRead: Date = Date.distantPast,
- rating: Int? = nil,
- status: Status = .onShelf
- ) {
- self.title = title
- self.author = author
- self.dateRead = dateRead
- self.rating = rating
- self.status = status
- }
- // implement the customMirror method to allow ReportKit to access the values for this class
- var customMirror:Mirror {
- Mirror(self, children: [
- "title": title,
- "author": author,
- "dateRead": dateRead,
- "rating": rating as Any,
- "status": status
- ])
- }
- }
- enum Status: Int, Codable, Identifiable, CaseIterable {
- case wantToRead, reading, completed
- var id: Self {
- self
- }
- var descr: String {
- switch self {
- case .wantToRead:
- "Want to Read"
- case .reading:
- "Reading"
- case .completed:
- "Completed"
- }
- }
- }
Related Articles
Using ReportKit with the DGCharts framework
ReportKit uses the DGCharts framework to generate charts (https://github.com/ChartsOrg/Charts). Importing ReportKit will give you access to all the classes within the DGCharts framework. You do not need to import DGCharts separately. If you have an ...
Upload Symbols Failed message when uploading to App Store Connect
While uploading your application to App Store Connect, you may get a warning similar to the following: The archive did not include a SYM for the ReportKit.framework with the UUIDs [54674DE7-25DA-3D87-A45E-1CB872947D51]. Ensure that the archive's dSYM ...