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!
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
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")
}
}
}
}
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 ...
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??!!]
The code below works fine on an iPad or iPhone -- saveDocument() writes to /Users/me/Library/Containers/My-App/Data/Documents, and openDocument() shows me the content of that folder. Beautiful.
On macOS, openDocument() shows the Documents folder at the root level of iCloud Drive, not the sandboxed version, which is local to my computer
It's like the documentPickerVC.directoryURL is being ignored. Why?? What am I doing wrong.
If it helps, the documentURL looks like this:
file:///Users/me/Library/Containers/org.me.My-App/Data/Documents/
Any help would be really, really appreciated!
func saveDocument(){
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
do {
let puzzleData = try? encoder.encode(puzzle)
						print("Saving: \(documentURL)")
let saveableURL = documentURL!.appendingPathComponent("\( .puzzle.date)")
try puzzleData!.write(to: saveableURL)
} catch {
displayError(title: "Error while saving document", message: "There was an error: \(error)")
}
}
// when the user taps on the Open button
@objc func openDocument(){
documentPickerVC = UIDocumentPickerViewController(forOpeningContentTypes: [UTType("public.item")!, UTType("public.data")!], asCopy: true )
documentPickerVC.delegate = self
documentPickerVC.modalPresentationStyle = .formSheet
documentPickerVC.directoryURL = documentURL
self.present(documentPickerVC, animated: true)
}
I want to override the highlight color for text in UITextFields (for a Mac Catalyst app) so that I can't actually see it. I've tried setting the tintColor property to UIColor.clear, but it has no effect: when I select text, behind it I see the color that the user selects in System Preferences General Highlight color.
Here is a picture of the problem: hi.stack.imgur.com/ku2iJ.png
The text is highlighted, but instead of yellow (the background color of the UITextField), it's showing the highlight color (blended with the yellow).
Is this a bug? What's the work around? Any hints would be greatly appreciated!