I'm working on a macOS SwiftUI app. I notice that Button text does not change color properly when the app changes between Dark and Light mode. Shouldn't the builtin Button be handling this automatically? The Text views seem to handle it fine and switch their text from white to black.
The Button text can become completely invisible when I go from Dark to Light mode. Restarting the app fixes it.
I can change the Dark/Light mode manually in System preferences, or it changes at certain times of day because I have it set, usually, to "Auto".
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Created
My app crashes and Xcode shows no stack trace. It just pops up some line of assembly language in __pthread_kill, and shows this in the console:
[error] precondition failure: invalid value type for attribute: 230424 (saw PreferenceKeys, expected ViewList) AttributeGraph precondition failure: invalid value type for attribute: 230424 (saw PreferenceKeys, expected ViewList).
Seems like a bug in SwiftUI. Any ideas? This is on macOS 11.
If I purchase a product with a test session in my unit test, everything works as expected. I see a purchased transaction on my payment queue.
But if I set the property to make it fail, nothing happens. Shouldn't I observe a transactions with transactionState == .failed?let session = try! SKTestSession(configurationFileNamed: "Configuration")
session.disableDialogs = true
session.clearTransactions()
session.failTransactionsEnabled = true
session.failureError = .unknown
session.buyProduct(productIdentifier: productID)
Has anyone used this?
This observer normally gets called. But not when I set failTransactionsEnabled. public func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
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)
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).
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 = ...
}
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?
Does anyone use this? I can't get it working. I'm talking about code in normal swift files, not playgrounds.Example:/// 
/// 
///Neither one displays anything in the documentation popover or the Quick Help Inspector.The docs act like it works: https://developer.apple.com/library/archive/documentation/Xcode/Reference/xcode_markup_formatting_ref/Images.html#//apple_ref/doc/uid/TP40016497-CH17-SW1A lot of my code would really benefit from diagrams in documentation. I'd love to be able to use this.
I've been using protocols to help model a hierarchy of different object types. As I try to convert my app to use SwiftUI, I'm finding that protocols don't work with the ObservableObject that you need for SwiftUI models. I wonder if there are some techniques to get around this, or if people are just giving up on "protocol oriented programming" when describing their SwftUI models? There is example code below. The main problem is that it seems impossible to have a View that with an model of protocol `P1` that conditionally shows a subview with more properties if that model also conforms to protocol `P2`.For example, I'm creating a drawing/painting app, so I have "Markers" which draw on the canvas. Markers have different properties like color, size, shape, ability to work with gradients. Modeling these properties with protocols seems ideal. You're not restricted with a single inheritance class hierarchy. But there is no way to test and down-cast the protocol...protocol Marker : ObservableObject {
var name: String { get set }
}
protocol MarkerWithSize: Marker {
var size: Float { get set }
}
class BasicMarker : MarkerWithSize {
init() {}
@Published var name: String = "test"
@Published var size: Float = 1.0
}
struct ContentView<MT: Marker>: View {
@ObservedObject var marker: MT
var body: some View {
VStack {
Text("Marker name: \(marker.name)")
if marker is MarkerWithSize {
// This next line fails
// Error: Protocol type 'MarkerWithSize' cannot conform to 'MarkerWithSize'
// because only concrete types can conform to protocols
MarkerWithSizeSection(marker: marker as! MarkerWithSize)
}
}
}
}
struct MarkerWithSizeSection<M: MarkerWithSize>: View {
@ObservedObject var marker: M
var body: some View {
VStack {
Text("Size: \(marker.size)")
Slider(value: $marker.size, in: 1...50)
}
}
}Thoughts?
I'm wondering how SwiftUI updates work in connection with ObservableObjects. If a SwiftUI View depends on an `ObservableObject`, the object's `objectWillChange` publisher fires, and SwiftUI learns about the change, before the change happens. At this point, SwiftUI can't re-render a View, right? Because the new properties aren't there yet. So what does SwiftUI do? Does it schedule the change for later? That doesn't make sense either - how can it know when the object will be ready to be used in a new rendering of the UI? ~ Rob
I'm surprised this simple code still doesn't work on iOS 13.3 / Xcode 11.3. On my iPhone SE it's almost all off screen.It's just two pieces of text, side by side, and two pickers, side by side. Anyone know a workaround? struct ContentView: View {
@State var choice: Int = 10
@State var choice2: Int = 10
var body: some View {
return VStack {
HStack {
Text("Some text here")
Spacer()
Text("Foo baz")
}
HStack {
Picker(selection: self.$choice, label: Text("C1")) {
ForEach(0..<10) { n in
Text("\(n) a").tag(n)
}
}
Picker(selection: self.$choice2, label: Text("C2")) {
ForEach(0..<10) { n in
Text("\(n) b").tag(n)
}
}
}
}
}
}
I have some code that used to run on my iPad Pro. Today I compiled it for iOS 13, with Xcode 11, and I get errors like this: validateComputeFunctionArguments:834: failed assertion `Compute Function(merge_layer): Shader uses texture(outTexture[1]) as read-write, but hardware does not support read-write texture of this pixel format.'The pixel format is showing as `MTLPixelFormatBGRA8Unorm`. That's what I expected.The debugger says the device has no support for writeable textures. (lldb) p device.readWriteTextureSupport (MTLReadWriteTextureTier) $R25 = tierNoneDid some devices lose support for texture writing in iOS 13?Rob
I'd like to use the new localization screenshots and test plans feature to take screenshots in different languages, for the app store. I end up with images that are half one screen and half another, like it's some kind of timing issue. My test code is below. Is it missing something that would give it the right timing on the screenshots?I wrote a UI test and set "Localization Screenshots" to "On" in the test plan's settings. The UI test walks through a few screens and the resulting test report has a few image files attached labeled "Localization screenshot". Some images are are split so that the left side is one view controller and the right side is another, like it captured a push navigation transition. Another image has two overlaid screens, each half faded.I'm running in the simulator. My test code looks like: func testTakeScreenshots() {
let app = XCUIApplication()
app.launch()
// At workouts page
app.tables["workouts"].cells.element(boundBy: 0).tap()
// At first workout
app.navigationBars.buttons["edit"].tap()
// At workout edit screen, click first exercise
app.tables.cells.element(boundBy: 0).tap()
...
}
Hi,I had a document-based iOS app working, but want to change it so it saves to a package. Seems like it's better when big chunks of a file may not be changing. In Xcode, under the Target > Info > Exported UTI > Conforms To, I had: "public.data, public.content". If I change that to "com.apple.package", then I can't open my old files to upgrade them. But if I *add* "com.apple.package", then the app opens both kinds as desired. I wonder if having it conform to all three of those types is going to cause other problems.Rob