Post

Replies

Boosts

Views

Activity

SwiftUI - Picker Binding not Working :-(
I am trying to bind a Picker, but it's not working. I create a BindableObject, an instance of Settings, add it to the environment using environmentObject() in SceneDelegate, and address it in the View using @EnvironmentObjectstruct ContentView : View { var favoriteFoods = ["Tofu", "Seitan", "Nilla Wafers", "Avocado Toast"] @EnvironmentObject var settings : Settings // meanwhile, inside var body: some View ... Picker(selection: $settings.favoriteFoodChoice, label: Text("Favorite Food")){ ForEach(self.favoriteFoods.identified(by: \.self)){ food in Text(food) } }Here's what my Settings looks like:class Settings : BindableObject { var didChange = PassthroughSubject<void,never>() var favoriteFoodChoice:Int { willSet { print("Favorite Food Choice will be \(newValue)") didChange.send() print("Favorite Food Choice: \(favoriteFoodChoice)")// never changes when I select a different food. } didSet { print("Favorite Food Choice was \(oldValue)") didChange.send() print("Favorite Food Choice: \(favoriteFoodChoice)")// never changes when I select a different food. } } init(favoriteFoodChoice:Int) { self.favoriteFoodChoice = favoriteFoodChoice } convenience init(){ self.init(favoriteFoodChoice:0) } }When I change the selected food, I see output from print(), but favoriteFoodChoice stays the same. Isn't it supposed to change?? Or am I misunderstanding how binding works with Pickers?Any help would be appreciated!
7
0
11k
Jul ’22
SwiftUI - Debug Preview not working in Xcode 12 beta 2?
Nothing prints to the console when I tap on a button, although the debugger will break on the print() lines. I've chosen Debug Preview rather than just Live Preview in the Canvas, and I've tried restarting Xcode. Before I file feedback, is anyone else seeing this?     var body: some View {         VStack(alignment: .leading){             Button("One Fish"){                 print("One")             }             Button("Two fish"){                 print("Two")             }         }     } }
22
0
8.6k
Sep ’21
Code to read from iCloud Drive works on Mac Catalyst and iOS Simulator, gives permission errors on physical iOS device - Why?
The code here works on Mac Catalyst, and on the iOS simulator; on a physical iOS device it throws an error on the try Data line with an error, NSCocoaErrorDomain Cocoa=257: "The file couldn't be opened because you don't have permission to view it." let puzzleParser = PuzzleParser() var pseudoPuzzleData: Data let urlToLoad = UserDefaults.standard.url(forKey: "lastSavedDocument") if urlToLoad != nil { let decoder = JSONDecoder() do { let result = urlToLoad?.startAccessingSecurityScopedResource() print("hello from loadInitialPuzzle(), \(result)") pseudoPuzzleData = try Data(contentsOf: urlToLoad!) urlToLoad?.stopAccessingSecurityScopedResource() AppDelegate.puzzle = try decoder.decode(Puzzle.self, from: pseudoPuzzleData) } catch // etc. Any ideas why this is happening, and what to do about it? I could really use some help here ...
1
0
927
Jul ’21
Why are dates all messed up in Google search of Developer Forums??
I don't know if this is a question for Google or Apple, but when I do a Google search that leads to results on developer.apple.com, Google reports dates that typically originate from June 2020. But when I go to the link, it's often for a question that's years older. For example, I just did a search on "delete all records from CloudKit zone en masse". The image shows the link -- it says Jun 20, 2020 -- but if I follow the link it shows the question was asked 4 years ago. Obviously date is hugely important when doing a search, why is this happening? [Tangential question: why won't Apple provide a utility to delete all the CloudKit records in a zone??!!]
1
0
764
Jul ’21
SwiftUI - Picker Binding not Working :-(
I am trying to bind a Picker, but it's not working. I create a BindableObject, an instance of Settings, add it to the environment using environmentObject() in SceneDelegate, and address it in the View using @EnvironmentObjectstruct ContentView : View { var favoriteFoods = ["Tofu", "Seitan", "Nilla Wafers", "Avocado Toast"] @EnvironmentObject var settings : Settings // meanwhile, inside var body: some View ... Picker(selection: $settings.favoriteFoodChoice, label: Text("Favorite Food")){ ForEach(self.favoriteFoods.identified(by: \.self)){ food in Text(food) } }Here's what my Settings looks like:class Settings : BindableObject { var didChange = PassthroughSubject<void,never>() var favoriteFoodChoice:Int { willSet { print("Favorite Food Choice will be \(newValue)") didChange.send() print("Favorite Food Choice: \(favoriteFoodChoice)")// never changes when I select a different food. } didSet { print("Favorite Food Choice was \(oldValue)") didChange.send() print("Favorite Food Choice: \(favoriteFoodChoice)")// never changes when I select a different food. } } init(favoriteFoodChoice:Int) { self.favoriteFoodChoice = favoriteFoodChoice } convenience init(){ self.init(favoriteFoodChoice:0) } }When I change the selected food, I see output from print(), but favoriteFoodChoice stays the same. Isn't it supposed to change?? Or am I misunderstanding how binding works with Pickers?Any help would be appreciated!
Replies
7
Boosts
0
Views
11k
Activity
Jul ’22
SwiftUI - Debug Preview not working in Xcode 12 beta 2?
Nothing prints to the console when I tap on a button, although the debugger will break on the print() lines. I've chosen Debug Preview rather than just Live Preview in the Canvas, and I've tried restarting Xcode. Before I file feedback, is anyone else seeing this?     var body: some View {         VStack(alignment: .leading){             Button("One Fish"){                 print("One")             }             Button("Two fish"){                 print("Two")             }         }     } }
Replies
22
Boosts
0
Views
8.6k
Activity
Sep ’21
Code to read from iCloud Drive works on Mac Catalyst and iOS Simulator, gives permission errors on physical iOS device - Why?
The code here works on Mac Catalyst, and on the iOS simulator; on a physical iOS device it throws an error on the try Data line with an error, NSCocoaErrorDomain Cocoa=257: "The file couldn't be opened because you don't have permission to view it." let puzzleParser = PuzzleParser() var pseudoPuzzleData: Data let urlToLoad = UserDefaults.standard.url(forKey: "lastSavedDocument") if urlToLoad != nil { let decoder = JSONDecoder() do { let result = urlToLoad?.startAccessingSecurityScopedResource() print("hello from loadInitialPuzzle(), \(result)") pseudoPuzzleData = try Data(contentsOf: urlToLoad!) urlToLoad?.stopAccessingSecurityScopedResource() AppDelegate.puzzle = try decoder.decode(Puzzle.self, from: pseudoPuzzleData) } catch // etc. Any ideas why this is happening, and what to do about it? I could really use some help here ...
Replies
1
Boosts
0
Views
927
Activity
Jul ’21
Why are dates all messed up in Google search of Developer Forums??
I don't know if this is a question for Google or Apple, but when I do a Google search that leads to results on developer.apple.com, Google reports dates that typically originate from June 2020. But when I go to the link, it's often for a question that's years older. For example, I just did a search on "delete all records from CloudKit zone en masse". The image shows the link -- it says Jun 20, 2020 -- but if I follow the link it shows the question was asked 4 years ago. Obviously date is hugely important when doing a search, why is this happening? [Tangential question: why won't Apple provide a utility to delete all the CloudKit records in a zone??!!]
Replies
1
Boosts
0
Views
764
Activity
Jul ’21