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
Post
Replies
Boosts
Views
Activity
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()
...
}
[edited down from my previous long-winded post]I’m using latest Catalina beta (7).I tried to turn on “Documents and Desktop” under System Preferences > Internet Accounts > iCloud options. It seems to have failed, and the checkbox does not stay on. It also seems to have deleted all my local files from ~/Documents and ~/Desktop, without actually moving them to iCloud. The files in iCloud drive have cloud icons and can’t be opened.Are the files in some hidden staging area? I can’t believe the system would delete them for real without successfully uploading them to iCloud first.If not, I hope my Time Machine backup works…
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
Hi,I need to save and load metal textures to a file. Example code below is below. I'm noticing the RGB values are changing as it gets saved and reloaded again.metal texture pixel: RGBA: 42,79,12,95after save and reload: 66,88,37,95I thought it might be a colorspace issue, but the colorspaces I’ve tried all had the same problem. `genericRGBLinear` got close, but there’s got to be a way to save the RGB data and get it back exactly. ?thanks,RobCode:// saving...
let ciCtx = CIContext()
let ciImage = CIImage(mtlTexture: metalTexture, options: [:])
[ … transfrom to flip y-coordinate …]
let colorSpace = CGColorSpaceCreateDeviceRGB()
let cgImage = ciCtx.createCGImage(ciImage, from: fullRect, format: kCIFormatRGBA8, colorSpace: colorSpace)!
let imageDest = CGImageDestinationCreateWithData(mData, kUTTypePNG, 1, nil)!
CGImageDestinationAddImage(imageDest, cgImage, nil)
CGImageDestinationFinalize(imageDest)
// loading...
let src = CGImageSourceCreateWithData(imgData, nil)
let img = CGImageSourceCreateImageAtIndex(src, 0, nil)
let loader = MTKTextureLoader(device: self.metalDevice)
let texture = try! loader.newTexture(cgImage: img, options: [:])
Hi,I'm trying to port this to Swift. https://developer.apple.com/documentation/metal/hello_triangleTo get it to run I had to add the following line to the renderer class. Any idea why it's not needed in the Objective-C version? pipelineStateDescriptor.depthAttachmentPixelFormat = metalView.depthStencilPixelFormatWithout it I get an error: -[MTLDebugRenderCommandEncoder validateFramebufferWithRenderPipelineState:]:1232: failed assertion `For depth attachment, the render pipeline's pixelFormat (MTLPixelFormatInvalid) does not match the framebuffer's pixelFormat (MTLPixelFormatDepth32Float).'Rob
Hi,Is there a way to embed a UIView inside the HTML laid out by WKWebView? Or, get the exact screen coordinates of an element, so that an overlaid sibling UIView could appear to be part of the HTML? I've got some rich text that I'm currently rendering with the WKWebView, and I'd like to create an animation around some of the text, using a UIView, not Javascript/HTML. I may also try UITextView, since the text is pretty simple.Rob
Hi,I have a lot of UIViews where the compiler forces me to add an init(coder:) initializer, like this:class FooView : UIView /* or a UIView subclass */ {
...
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
...
}It claims it's required but my program runs fine without it. I do not create the views from an archive.This makes me wonder if something is wrong here with the design of the library, or the concept of a 'required' initializer. What do people think? Does it make sense or is this a wart? If so, can it be fixed?Rob