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)
Post
Replies
Boosts
Views
Activity
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."
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).
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.)
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.
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 {
		self.foo = ...
		self.bar = ...
}
Do I need to protect against races when calling the promise that completes the Future?
let future = Future<Int,Never> { promise in
		savedPromise = promise
}
// later...
// in thread #1
savedPromise?(1)
// in thread #2
savedPromise?(2)
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.)
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?
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
		switch result {
				case .success(let message): ...
				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?
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 > A > B". I edit something in B and I get an unwanted pop animation back to "Root > A", and then it immediately pushs again so it's back to "Root > A > B". ~ R
Hi,I watched a WWDC 2019 video about using Core Data and CloudKit. They showed a sample app, and said it was available, but I don't see it anywhere. Where is it?thanks,R.
I have a UI where you can navigate/push views like this: Root view > List of things > View thing > 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?
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 <x-coredata://6C618B32-5866-4E35-93C9-3B7F3D221FE6/MyObject/p7>' with oldVersion = 4 and newVersion = 5 and old object snapshot = {\n isActive = 0;\n mostRecentEvent = \"<null>\";\n name = \”Foo\”;\n notes = \"<null>\";\n} and new cached row = {\n isActive = 0;\n mostRecentEvent = \"<null>\";\n name = \”Foo\”;\n notes = \"<null>\";\n}"), NSExceptionOmitCallstacks=true}:
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