Post

Replies

Boosts

Views

Activity

Buttons not responding to taps
I have a fairly complex view (nested 5-6 stacks deep) that is navigated to from another view. This complex view contains a custom view (with gestures attached), half a dozen buttons, a slider, a couple of pickers, a toggle, and a couple of steppers. Everything is working as expected on both iOS and OSX, *except* 5 of the buttons. These do not respond to presses (or TapGesture if attach one that prints a message), *except* in 2 cases. (1) if I click on one of the buttons a lot in different spots in its frame, eventually it seems to get a click (100+ attempts hammering the mouse or tapping the screen). (2) on OSX if I resize the window horizontally by a considerable amount, the button in the bottom left corner starts working as expected. Suspecting some sort of an "overlap" issue I've gone through the whole view heirarchy drawing the view frames and adding TapGesture with prints, but failed to find anything that might be stealing the buttons' taps.What could be causing my buttons to not get their clicks?
0
0
632
May ’20
Rendering drawingGroup while dragging
I have a custom SwiftUI view that renders something which is vastly larger than the viewable area, and allows the user to drag the view around to see different portions of it. My view is composed of a large number of paths (thousands) and therefore it has a drawingGroup() on it so that it performs reasonably. Unfortunately, when I add this drawingGroup() then view no longer renders portions of the view that were out-of-frame before dragging started. From what I've read, the drawingGroup is moving the rendering into an offscreen buffer, so I assume that the issue is that this buffer is not being updated during the gesture. Is there a way to have the offscreen buffer update during dragging, or, alternatively, oversize the buffer by 3x in each dimension so that dragging has a large enough field to scroll within?
0
0
290
May ’20
GPU capture crash using Metal from SwiftUI
I am adopting direct use of Metal (via MTKView) in my SwiftUI app's custom view. Currently I am trying to add a second rendered primitive (a point with a custom shader) but it isn't working as expected so I want to debug it. When I click the GPU frame capture button, the program immediately crashes on my call to commandBuffer.commit(). Thinking this is related some something I'm doing wrong in my second rendered primitive, I comment it out and try again -- the crash is identical. At this point the only thing I am rendering in Metal (and it works perfectly until I frame capture) is a single full-view textured quad.Running latest Catalina on a 2018 Mac mini with an eGPU, latest Xcode, Mac build. Running an iOS build on an iPadPro (1st gen) the frame capture works and I'm able to debug the frame.Here is the crash's stack trace:Thread 1 Queue : com.apple.main-thread (serial)#0 0x00007fff6e987613 in ___lldb_unnamed_symbol61$$libMTLCapture.dylib ()#1 0x00007fff6e9c2310 in ___lldb_unnamed_symbol578$$libMTLCapture.dylib ()#2 0x00007fff6e9d28b8 in ___lldb_unnamed_symbol838$$libMTLCapture.dylib ()#3 0x00007fff6e9dca4e in ___lldb_unnamed_symbol1034$$libMTLCapture.dylib ()#4 0x00007fff6e9dc686 in ___lldb_unnamed_symbol1021$$libMTLCapture.dylib ()#5 0x00007fff6e9b5663 in ___lldb_unnamed_symbol415$$libMTLCapture.dylib ()#6 0x00007fff6e9b5568 in ___lldb_unnamed_symbol414$$libMTLCapture.dylib ()#7 0x00000001000201de in SpaceView.Coordinator.draw(in:) at /Volumes/HelixRust/Development/NewtonSpace/NewtonSpace/SpaceView.swift:401#8 0x00000001000204c4 in @objc SpaceView.Coordinator.draw(in:) ()#9 0x00007fff73bdd644 in -[MTKView draw] ()#10 0x00007fff437dcb84 in -[CALayer display] ()#11 0x00007fff437dc469 in CA::Layer::display_if_needed(CA::Transaction*) ()#12 0x00007fff437ba716 in CA::Context::commit_transaction(CA::Transaction*, double) ()#13 0x00007fff437b9304 in CA::Transaction::commit() ()#14 0x00007fff437f5725 in CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) ()#15 0x00007fff37cfb4f5 in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()#16 0x00007fff37cfb427 in __CFRunLoopDoObservers ()#17 0x00007fff37cfa039 in CFRunLoopRunSpecific ()#18 0x00007fff3692dabd in RunCurrentEventLoopInMode ()#19 0x00007fff3692d7d5 in ReceiveNextEventCommon ()#20 0x00007fff3692d579 in _BlockUntilNextEventMatchingListInModeWithFilter ()#21 0x00007fff34f78c99 in _DPSNextEvent ()#22 0x00007fff34f774e0 in -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] ()#23 0x00007fff34f691ee in -[NSApplication run] ()#24 0x00007fff34f3aff6 in NSApplicationMain ()#25 0x00007fff3525ca85 in _NSApplicationMainWithInfoDictionary ()#26 0x00007fff68ea5e00 in UINSApplicationMain ()#27 0x00007fff7858c6ff in UIApplicationMain ()#28 0x0000000100005d7b in main at /Volumes/HelixRust/Development/NewtonSpace/NewtonSpace/AppDelegate.swift:74#29 0x00007fff71c42cc9 in start ()#30 0x00007fff71c42cc9 in start ()
2
0
2.4k
Jun ’20
Swift UI Text view of interpolated string with observed object state not updating
I have a view with a couple of subviews whose text is created using string interpolation with fields and function results from an observed object. For example, Button("\(self.obj.get_value(self.obj.selection))") { 		self.obj.make_a_change(self.obj.selection) } NavigationLink(destination: MyFormView(self.obj)) { Text("\(self.obj.array[self.obj.selection])") } Where the class contains: 		@ObservedObject var obj : MyClass And in that class the array and selection members are @Published. Many other views are using data from the observed object and displaying/updating correctly. It seems like SwiftUI somehow isn't figuring out that the strings are dependent upon the observed object, and I haven't been able to figure out a way to make it aware of this dependency (in SwiftUI 1.0... it looks like 2.0 might be adding an onChange modifier, but I cannot upgrade yet). How can I get my views with interpolated strings to update properly?
2
0
810
Jul ’20
Swift -- how to init a member variable which is a class reference
class A { 		init(_ p: String) {...} } struct B { 		var a : A 		init(_ p: String) { 				self.a = A(p) 		} } This fails to compile because it claims that a is being used before being initialized. I can't do it in the var a : A declaration line because I need to use the initialization argument. I can't make a optional because its actually an ObservableObject and I need to use the self.$a.keypathhere syntax on it which clashes badly with it being optional (plus a isn't really optional, its just this annoying initialization problem). How to solve this dilemma?
5
1
1.7k
Jul ’20
Tracking down the source of mutation causing view updates
Two questions here: 1) I have a fairly complex SwiftUI app which is in certain situations updating its views far more than I expect it to be. It seems that something in the data model is appearing (to the framework) to be changing much more often than I expect it to. Are there any good tools for tracking this down? 2) One thing I tried is to use Combine to subscribe to all the publishers I suspect of being possible culprits, and print a message from each one's sink(receiveValue:). Sure enough, I've found one that is publishing unexpected updates... but I'm not sure why. The data in question is a struct that contains a dictionary (which is used as a cache of previously computed values), and has a member function for retrieving a value. This function is marked as mutating because it sometimes needs to add to the cache dictionary. As long as the requested key is present in the dictionary cache, however, it returns an existing value. The problem I am seeing is that even when only asked for the same value over and over again, it publishes updates. So is calling a mutating function enough to trigger a published update, even if it doesn't actually change the struct? If so, how can I avoid this without externalizing the fact that there is a cache and that the client of the object must first check the cache and then do the mutation if it didn't find what it wanted?
1
0
349
Jul ’20
Two lists in a view getting their text confused
I have a Form with two List sub-views, each in its own section. I populate these with the basic ForEach range pattern: Form { &#9;&#9;Section { &#9;&#9;&#9;&#9;List { &#9;&#9;&#9;&#9;&#9;&#9;ForEach(0..<array1.count, id: \.self) { idx in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;NavigationLink(another_view_1()) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text(array1[idx].name) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;} &#9;&#9;Section { &#9;&#9;&#9;&#9;List { &#9;&#9;&#9;&#9;&#9;&#9;ForEach(0..<array2.count, id: \.self) { idx in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;NavigationLink(another_view_2()) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text(array2[idx].name) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;} } The first list works fine. When I scroll down to the second list, some of the names (and navigation links and their destination views) are from the first list! The name properties for some of the elements of the second list are invoked, and they show up properly. Some elements don't have the name property invoked, however, and they show up (and work as if) they were from the first list. This seems like an outright bug in SwiftUI -- anyone seen it before? Are there any work arounds?
3
0
1.8k
Jul ’20
How to get NavigationLink back button text back?
I have a few views arranged as navigation pages with the standard back buttons, titles, etc. Initially the automatically provided back button had the title of the preceding page, but when I added a title to the destination page, the title of the page you're going back to disappeared. I would like to have both the local title and the back button label. How can I ensure that? Space isn't a problem as the strings are relatively short and the smallest screen I'm dealing with is an iPad.
1
0
851
Aug ’20
CompileAssetCatalog failure due to having an asset for older iOS release
I have a SwiftUI project that I'm trying to build for my iPadPro running iOS 14.1, but ever since updating to the latest Xcode and upgrading the iPad to iOS 14, I've been getting this build error: .../Assets.xcassets:1:1: 76x76@1x app icons only apply to iPad apps targeting releases of iOS prior to 10.0. I tried removing the 76x76 app icon, however then it complained about that too. I can run & test my app on iOS with this error, but the Mac build works fine. I also see this further up in the build log: 2020-10-30 20:50:35.012 ibtoold[23910:1459929] Error Domain=com.apple.CoreSimulator.SimError Code=400 "Unable to determine SimDeviceSet, set_path=(null)" UserInfo={NSLocalizedDescription=Unable to determine SimDeviceSet, set_path=(null), NSUnderlyingError=0x7fb55cc61c00 {Error Domain=NSPOSIXErrorDomain Code=12 "Cannot allocate memory" UserInfo={NSLocalizedFailureReason=Allocation or initialization failed., NSLocalizedDescription=Failed to initialize simulator device set.}}} /* com.apple.actool.errors */ : error: Failed to find a suitable device for the type IBSimDeviceTypeiPad2x (com.apple.dt.Xcode.IBSimDeviceType.iPad-2x) with runtime iOS 14.1 (14.1 - 18A8394) - com.apple.CoreSimulator.SimRuntime.iOS-14-1     Failure Reason: Failed to create SimDeviceSet at path /Users/andrew/Library/Developer/Xcode/UserData/IB Support/Simulator Devices. You'll want to check the logs in ~/Library/Logs/CoreSimulator to see why creating the SimDeviceSet failed.     Underlying Errors:         Description: Failed to initialize simulator device set.         Failure Reason: Failed to subscribe to notifications from CoreSimulatorService.         Underlying Errors:             Description: Unable to determine SimDeviceSet, set_path=(null)             Underlying Errors:                 Description: Failed to initialize simulator device set.                 Failure Reason: Allocation or initialization failed.
2
0
1.6k
Oct ’20
SwiftUI 2.0 Mac sliders & steppers stop working after button press
Am moving a SwiftUI 1.0 app (MacOS & iPadOS) to 2.0, and running into some strange view problems. I have a fairly complex screen (custom view plus 4 sliders, 6 steppers, and about a dozen buttons) which was working properly under SwiftUI 1.0. With 2.0, it is working fine on iPad. And on Mac ... initially. Once I've pressed a button in the Mac version, however, the sliders and steppers stop responding to input until I navigate away from the view and come back. The controls are all referring to published fields of an observed object. Have also noticed that the onChanged member of the DragGesture on the custom view isn't being called, but the onEnded is (also on Mac only, although there seems to be some other issue on iPad). Has anyone seen similar issues?
2
0
568
Dec ’20
Strange object construction behaviour
I stumbled across this behaviour, and have excised it from my code, but I would like to understand why it was happening. The following code (with names changed to protect the innocent) was causing two instances of MyClass to be instantiated... why? It seems like the StateObject ought to be set to the newly instantiated wrappedValue, and then the global gObj optional set to refer to that object. Also, that appears not to be the case, and a second MyClass gets instantiated (demonstrated by a print or breakpoint in its init method). var gObj: MyClass? @main struct MyApp : App { @StateObject(wrappedValue: MyClass()) public var obj : MyClass &#9;&#9;init() { &#9;&#9;&#9;&#9;gObj = self.obj &#9;&#9;} var body: some Scene { WindowGroup { ContentView(obj: self.obj) } } }
1
0
275
Dec ’20