Posts

Post marked as solved
3 Replies
14k Views
In watchOS I want to change the size and foreground color of a ProgressView. In Apple's example they use a separate struct to customize the appearance of the ProgressView. However I can't seem to resize the ProgressView beyond its default. I've tried using .frame with no luck. And .foregroundColor appears to have no effect as far as I can tell either. Has anyone had any luck customizing the new ProgressView with Xcode12 and SwiftUI 2.0? struct ContentView: View { @State private var progressAmount = 0.0 let timer = Timer.publish(every: 0.1, on: .main, in: .common).autoconnect() var body: some View { ProgressView("Progress…", value: progressAmount, total: 100) .progressViewStyle(DarkBlueShadowProgressViewStyle()) .progressViewStyle(CircularProgressViewStyle()) .onReceive(timer) { _ in if progressAmount < 100 { progressAmount += 2 } } } } struct DarkBlueShadowProgressViewStyle: ProgressViewStyle { func makeBody(configuration: Configuration) -> some View { ProgressView(configuration) .shadow(color: Color(red: 0, green: 0, blue: 0.6), radius: 4.0, x: 1.0, y: 2.0) } }
Posted
by DanOLeary.
Last updated
.
Post not yet marked as solved
1 Replies
909 Views
In Xcode 12 beta 2 I want my ComplicationController to make a FetchRequest in order to update my complications but I am having trouble injecting the persistent store into the environment. I should note this is a pure SwiftUI App in watchOS where the app entry point is the @main struct. There is no ExtensionDelegate or HostingController. For the watchOS app itself this is how I'm setting up the PersistentContainer: struct RunPlanner: App { @Environment(\.scenePhase) private var scenePhase @StateObject private var persistentStore = PersistentStore.shared @ObservedObject var selection = TabSelection() var body: some Scene { WindowGroup { TabView(selection: $selection.currentTab) { WatchAddRunView(tabSelection: selection) .tag(0) ContentView() .tag(1) } .environment(\.managedObjectContext, persistentStore.context) .animation(.easeIn) } .onChange(of: scenePhase) { phase in switch phase { case .active: print("\(#function) REPORTS - App change of scenePhase to ACTIVE") case .inactive: print("\(#function) REPORTS - App change of scenePhase to INACTIVE") case .background: print("\(#function) REPORTS - App change of scenePhase to BACKGROUND") savePersistentStore() default: print("\(#function) REPORTS - App change of scenePhase Default") } } } func savePersistentStore() { persistentStore.saveContext() } } This works for the app itself to save values to CoreData however my ComplicationController is not seeing the NSPersistentStoreContainer and I'm not sure how to inject it. My current attempt within my ComplicationController class is this: class ComplicationController: NSObject, CLKComplicationDataSource { @Environment(\.managedObjectContext) var moc let request = NSFetchRequest&lt;RunEvents&gt;(entityName: "RunEvents") ....complication code... } func getSavedRunName() -> String { var activeName = "Run Roster" do { let savedRuns = try moc.fetch(request) savedRuns.forEach({ if $0.isActive { guard let fetchedName = $0.name else { return } activeName = fetchedName } }) } catch { print("Error in Fetch Request") } return activeName } However the getSavedRunName method will cause the app to crash on execution with the debugger saying "reason: '+entityForName: nil is not a legal NSPersistentStoreCoordinator for searching for entity name 'RunEvents''" I've searched and fumbled around for various solutions with no positive results. Any insight here is very much appreciated. Dan
Posted
by DanOLeary.
Last updated
.
Post not yet marked as solved
1 Replies
1.2k Views
The Coffee Tracker sample app's complication code is set for a deployment target of watchOS 6.2 and this is a code block for a complication from the sample;  // Return a circular small template.     private func createCircularSmallTemplate(forDate date: Date) -> CLKComplicationTemplate {         // Create the data providers.         let mgCaffeineProvider = CLKSimpleTextProvider(text: data.mgCaffeineString(atDate: date))         let mgUnitProvider = CLKSimpleTextProvider(text: "mg Caffeine", shortText: "mg")         // Create the template using the providers.         let template = CLKComplicationTemplateCircularSmallStackText()         template.line1TextProvider = mgCaffeineProvider         template.line2TextProvider = mgUnitProvider         return template     } Changing the deployment target to watchOS 7.0 will produce this error: 'init()' was deprecated in watchOS 7.0: Initializing a template without parameters is deprecated in watchOS 7.0. Use an init with parameters instead. I have set up my own complications to supposedly align with the new init() requirements, however my complication is not showing up in the list of available options. Have I done something incorrect in this example?  Thank you - Dan func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) {         switch complication.family { case .circularSmall: let line1 = CLKSimpleTextProvider(text: "Run Roster") let line2 = CLKSimpleTextProvider(text: "10 Sep 2021") let circularSmall = CLKComplicationTemplateCircularSmallStackText(line1TextProvider: line1, line2TextProvider: line2) handler(circularSmall) ... // more switch cases below
Posted
by DanOLeary.
Last updated
.