Post

Replies

Boosts

Views

Activity

Reply to How to save settings selections
import SwiftUI struct CardTheme: View { //@State private var theme = 0 @State private var theme = UserDefaults.standard.integer(forKey: "Card Theme") var body: some View { List { HStack { Text("Mono") //.font(.system(size: 12)) .onTapGesture { self.setTheme(i: 0) } Spacer() if(theme == 0) { Image(systemName: "checkmark") .foregroundColor(Color.green) } } HStack { Text("Cool") // .font(.system(size: 12)) .onTapGesture { self.setTheme(i: 1) } Spacer() if(theme == 1) { Image(systemName: "checkmark") .foregroundColor(Color.green) } } HStack { Text("Cute") // .font(.system(size: 12)) .onTapGesture { self.setTheme(i: 2) } Spacer() if(theme == 2) { Image(systemName: "checkmark") .foregroundColor(Color.green) } } } .navigationBarTitle(Text(verbatim: "Card Theme")) } func setTheme(i: Int) { theme = i UserDefaults.standard.set(i, forKey: "Card Theme") } }Sorry I'm having trouble following your code. But if I modified mine to use UserDefaults, i can see that it is correctly saving and retrieving the selection as I can close the app and re-open it and have the correct theme row ticked. The only issue is when I go back to the previous view and re-enter the Card Theme view, it is still showing the same selection as from when the app loaded, rather than any changes in selection since the app loaded. Is there a quick fix for that? For example can I incorporate @EnvironmentObject? Thanks.
Nov ’19
Reply to How to track down "precondition failure: attribute failed to set an initial value: ???" errors?
Hi, I've recently been getting precondition failure: invalid input index: 2 errors too after the latest Xcode 11.4 update. I use GeometryReader to read the user's Watch screen size so i can draw a frame that is relative in size. Unfortunately NavigationView is not available on WatchOS so I'm not sure what other solutions are available. Do you have any ideas? Thanks.
Mar ’20
Reply to How does notification registration work in the SwiftUI app lifecycle?
I put it inside applicationDidFinishLaunching as follows: notificationCenter = UNUserNotificationCenter.current() 		notificationCenter.removeAllPendingNotificationRequests() 		let options: UNAuthorizationOptions = [.alert, .sound, .badge] 		notificationCenter.requestAuthorization(options: options) { 			(didAllow, error) in 			if !didAllow { 				print("User has declined notifications") 			} 		}
Jun ’20
Reply to How to chain speech utterances
I tried the code you posted above: let synth = AVSpeechSynthesizer() let cantoUtterance = AVSpeechUtterance(string: chinese) cantoUtterance.voice = AVSpeechSynthesisVoice(identifier: "com.apple.ttsbundle.Sin-Ji-compact") synth.speak(cantoUtterance) let mandoUtterance = AVSpeechUtterance(string: chinese) mandoUtterance.voice = AVSpeechSynthesisVoice(language: "zh-CN") synth.speak(mandoUtterance) and on my Watch I only hear the first utterance.
Jun ’20