Hi,
I keep getting the error "Type '()' cannot conform to 'View'; only struct/enum/class types can conform to protocols" on lines 99 and 100, here is the code:
Thanks in advance
I keep getting the error "Type '()' cannot conform to 'View'; only struct/enum/class types can conform to protocols" on lines 99 and 100, here is the code:
Code Block import WidgetKit import SwiftUI import Intents import UserNotifications class Riddles { static var text = String() static var isWednesday = Bool() static func largeWidget() { Riddles.checkWeekday() let userDefaults = UserDefaults(suiteName: "group.SetRiddle") if Riddles.isWednesday == false { if userDefaults?.value(forKey: "currentRiddle") != nil || userDefaults?.value(forKey: "previousRiddle") != nil { Riddles.text = "\(UserDefaults(suiteName: "group.SetRiddle")?.value(forKey: "currentRiddle") as! String) \n\n\(UserDefaults(suiteName: "group.SetRiddle")?.value(forKey: "previousRiddle") as! String)" }else{ Riddles.text = "Please open app to display riddle" } }else { Riddles.text = "Please open app to display riddle" } } static func mediumWidget() { Riddles.checkWeekday() let userDefaults = UserDefaults(suiteName: "group.SetRiddle") if Riddles.isWednesday == true { if userDefaults?.value(forKey: "currentRiddle") != nil { Riddles.text = UserDefaults(suiteName: "group.SetRiddle")?.value(forKey: "currentRiddle") as! String }else{ Riddles.text = "Please open app to display riddle" } }else { Riddles.text = "Please open app to display riddle" } } static func checkWeekday() { let today = Date() let calendar = Calendar(identifier: .gregorian) let components = calendar.dateComponents([.weekday], from: today) if components.weekday == 4 { Riddles.isWednesday = true }else { Riddles.isWednesday = false } } } struct Provider: IntentTimelineProvider { func placeholder(in context: Context) -> SimpleEntry { SimpleEntry(date: Date(), text: "", configuration: ConfigurationIntent()) } func getSnapshot(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (SimpleEntry) -> ()) { let entry = SimpleEntry(date: Date(), text: "", configuration: configuration) completion(entry) } func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline<Entry>) -> ()) { var entries: [SimpleEntry] = [] // Generate a timeline consisting of five entries an hour apart, starting from the current date. let currentDate = Date() for hourOffset in 0 ..< 5 { let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)! let entry = SimpleEntry(date: entryDate, text: "", configuration: configuration) entries.append(entry) } let timeline = Timeline(entries: entries, policy: .atEnd) completion(timeline) } } struct SimpleEntry: TimelineEntry { let date: Date let text: String let configuration: ConfigurationIntent } struct RiddleWidgetEntryView : View { var entry: Provider.Entry @Environment(\.widgetFamily) var family: WidgetFamily @ViewBuilder var body: some View { switch family { case .systemMedium: Riddles.mediumWidget() case .systemLarge: Riddles.largeWidget() } ZStack { Text(Riddles.text) .foregroundColor(.black) .font(Font.system(size: 20)) } } } @main struct RiddleWidget: Widget { let kind: String = "RiddleWidget" var body: some WidgetConfiguration { IntentConfiguration(kind: kind, intent: ConfigurationIntent.self, provider: Provider()) { entry in RiddleWidgetEntryView(entry: entry) } .configurationDisplayName("My Widget") .description("This is an example widget.") .supportedFamilies([.systemMedium, .systemLarge]) } } struct RiddleWidget_Previews: PreviewProvider { static var previews: some View { RiddleWidgetEntryView(entry: SimpleEntry(date: Date(), text: "This Weeks Riddle: ", configuration: ConfigurationIntent())) .previewContext(WidgetPreviewContext(family: .systemSmall)) } }
Thanks in advance