Post

Replies

Boosts

Views

Activity

Bad: OutlineGroup is not lazy loading children?
This appears to severely limit the usefulness of hierarchical lists in SwiftUI. I want to use the new hierarchical list/outline to display a filesystem tree. For data to pass to OutlineGroup, I created a class named FileSystemNode, and gave it a computed children property. When the getter is first called, it will read its directory contents to return a list (if it is a directory). Problem is, when the OutlineGroup is first displayed, even though it is collapsed on-screen to a single node, it calls children and recurses over the entire filesystem. Is there a way to stop this? If not, I hope it gets fixed before release. (This is on macOS Big Sur beta)
3
2
1.7k
Oct ’20
How to build a replacement for sandbox-exec?
Hi, I want something like sandbox-exec, so I can run things that I don't trust, and restrict their ability to read or write files to only certain locations. Like most software devs I have to download and run lots of code from the internet and the danger of this really annoys me. Unfortunately sandbox-exec is marked as deprecated and the APIs in sandbox.h say "No longer supported". I notice there is some new stuff in the Apple docs about "hypervisors" and "virtualization". https://developer.apple.com/documentation/hypervisor https://developer.apple.com/documentation/virtualization Would these APIs allow me to start and control a virtual copy of my macOS, to serve like a sandbox? Are there other solutions that people use? As an example, say that I need to download and run a copy of memcached. It's a typical open source project – you unpack a source tgz, then run configure; make and get a binary. Now I want to run that without worrying that some hacker injected a piece of evil code to copy my files and send them somewhere. So I want to say "run this binary, while disallowing file reads and writes, except for directories X,Y,Z, and disallowing network connections, except for listening on port 1234."
11
0
3.9k
Sep ’20
Hierarchical List / OutlineGroup - can't change data?
Does anyone use the new hierarchical data List (ie, OutlineGroup) with a model where the tree data changes? I'm on Big Sur beta. I have code like this: List([treeRoot], children: \.children) { item in ... Say the treeRoot (observed object) gets a new child. The view tries to re-render and fails: 2020-09-21 ... [General] NSOutlineView error inserting child indexes <_NSCachedIndexSet: 0x600000760000>[number of indexes: 1 (in 1 ranges), indexes: (3)] in parent 0x0 (which has 1 children).
1
0
720
Sep ’20
Why do some keybindings not have the delete (-) button to remove?
I'm trying to edit my keybindings in Xcode's preferences. Sometimes when I click a binding, I get the "-" button to remove it, but other times I don't. For example, in Xcode 12 now, the shortcut for "Analyze (Product Menu)" has no way to remove it. I rarely use this and I don't want it taking up a binding. (I also wish Xcode would allow multi-stroke bindings like Emacs and IntelliJ. I can make more mnemonic bindings that way. But that's another story.)
0
0
257
Sep ’20
Health data like daily grams of protein in Core Data CloudKit container?
Hi, I wrote an app that helps me count how many grams of protein I eat each day. I'm the only user now, and the app uses Core Data and the CloudKit container, to sync data across my devices. I was thinking about releasing it in App Store, and I noticed this in the app review guidelines: may not store personal health information in iCloud. Does that mean we cannot use Core Data with NSPersistentCloudKitContainer for an app like this? Thanks.
0
0
326
Jul ’20
Still wondering about objectWillChange (vs objectDidChange) magic :)
Hi all, The WWDC video offers (at about 16:45) as short explanation as to why it's "objectWillChange" instead of "objectDidChange". He said it's because SwiftUI needs to coalesce the changes. Okay, but then how does it know when the changes have ended? It seems like you'd need two events. Something like: self.objectWillChange.send() self.foo = ... self.bar = ... self.objectHasFinishedChanging.send() or self.objectChanges { &#9;&#9;self.foo = ... &#9;&#9;self.bar = ... }
4
0
2.3k
Jun ’20
Setting @State AnyCancellable? to nil doesn't deallocate/cancel?
Does @State keep hidden copies of it's previous values somewhere? I have a button that starts an async process. The button handler subscribes to a Combine publisher and saves the AnyCancellable in a @State var. Later, a cancel button sets the state var to nil. @State private var mySubscription: AnyCancellable? = nil When I set that to nil again, the subscription is not deallocated. If I make the simple change of moving mySubscription to a global var, or a property of an observed object, then it works as expected - the subscription is cancelled and deallocated. (This is SwiftUI 2019, Xcode 11, not the new beta stuff.)
1
0
873
Jun ’20
Why does Publisher.multicast take a Subject?
From what I can gather so far, the result of multicast is much like the result of share, except the multicast publisher has a connect() method, so it let's you set up multiple subscribers before starting the flow of data. But from that understanding, the signature might as well be multicast(), not multicast(subject: Subject). What is the subject good for?
4
0
579
Jun ’20
Web socket - how to get error when other side closes?
I'm trying to communicate with my server using web sockets (URLSession, URLSessionWebSocketTask) let task = URLSession.shared.webSocketTask(with: url) task.send(.data(...)) { ... } task.receive { result in &#9;&#9;switch result { &#9;&#9;&#9;&#9;case .success(let message): ... &#9;&#9;&#9;&#9;case .failure(let error): ... When the server has an internal error and closes the connection, I don't get anything here in Swift on the client side. I've got a chain of Combine Publishers and I end up timing them out after 60 seconds. Shouldn't the .failure path get called if the connection goes down? Is there another way to get that error when it happens, without waiting for the timeout?
2
0
1.3k
Jun ’20
Spurious pop and re-push during state changes
Hi,I've got a hard-to-reproduce bug where my views pop off the `NavigationView` stack and then re-push during state changes. I'm not sure what the heck is causing it yet. If this is a familiar problem to anyone, please let me know. In other words I have a navigation stack like: "Root &gt; A &gt; B". I edit something in B and I get an unwanted pop animation back to "Root &gt; A", and then it immediately pushs again so it's back to "Root &gt; A &gt; B". ~ R
7
0
1.8k
Jun ’20
Popping back multiple levels?
I have a UI where you can navigate/push views like this: Root view &gt; List of things &gt; View thing &gt; Edit thingThe "Edit thing" view can also delete it. After a delete, I want it to pop back to the "List of things". Best I've got now is to call `presentationMode.wrappedValue.dismiss()` on the "Edit thing" view, and then again in the "View thing" view, but that time inside DispatchQueue.main.async { }. It works but the double animation is kind of clunky.Is there a better way?
3
0
7.0k
Jun ’20
CloudKit, 2 quick saves, error: "Could not merge changes"
I'm experimenting with Core Data and CloudKit using the recommended `NSPersistentCloudKitContainer`. I'm kind of new to Core Data so maybe I'm doing something simple/stupid. I get an error when changing the object twice, quickly.I have a SwiftUI view of one of my managed objects, with button toggle the "isActive" property. If I tap it twice in a row, I get an error from `NSManagedObjectContext.save`. How do you prevent or recover from this kind of error?It seems to be a timing thing, because I'm having trouble duplicating it. private func toggleActiveState() { exercise.isActive = !exercise.isActive try! moc.save() // error }RobFatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=133020 "Could not merge changes." UserInfo={conflictList=( "NSMergeConflict (0x282fb15c0) for NSManagedObject (0x2819ca8a0) with objectID '0xb61bc172bb432131 &lt;x-coredata://6C618B32-5866-4E35-93C9-3B7F3D221FE6/MyObject/p7&gt;' with oldVersion = 4 and newVersion = 5 and old object snapshot = {\n isActive = 0;\n mostRecentEvent = \"&lt;null&gt;\";\n name = \”Foo\”;\n notes = \"&lt;null&gt;\";\n} and new cached row = {\n isActive = 0;\n mostRecentEvent = \"&lt;null&gt;\";\n name = \”Foo\”;\n notes = \"&lt;null&gt;\";\n}"), NSExceptionOmitCallstacks=true}:
1
0
854
Jun ’20
Do we need a local modificationDate field?
I see the CKRecord class has a `modificationDate: Date`, but I'm tempted to add my own field for resolving conflicts, because that field represents the time the record was saved in CloudKit, not the time the change was actually made on the local device. Imagine...- At time t=1, record A changes on device 1.- At t=2, record A changes on device 2.- At t=3, record A uploads to CloudKit from device 1.- At t=4, device 2 see the change to A from device 1 and tries to resolve a conflict with "last writer wins". If it looks at the CKRecord.modificationDate, it will see the modificationDate as t=3 and it will overwrite the change from device #2 at t=2. In reality the time of the change from device #1 was t=1 and device #2's change should win.Rob
7
0
655
Jun ’20