Post

Replies

Boosts

Views

Activity

actors, SwiftUI and @Published
Hi, is there a way that an actor can have a @MainActor @Published annotated property which is then consumed by a SwiftUI View "as usual"? Currently this: @Published @MainActor public private(set) var state: State = .initial gives me the following error when trying to access it from with a SwiftUI View: "Actor-isolated property '$state' can only be referenced from inside the actor" I guess I understand where the error is coming from, but I wonder if there's a way to publish properties from actors and be able to make sure they are updated on the main thread by annotating them with @MainActor.
1
0
4.0k
Aug ’21
Selection state is lost when navigating to/from home screen
Hi! When using the Sample "NavigationCookbook" in the two column layout, the selection in the first column is not remembered, when navigating to the Home Screen and back. This behaviour can be reproduced by starting the app on the iPad or simulator, selecting for example "Pancake" and then navigating to the home screen and back into the navigation. Sometimes this (the navigation to/back from the home screen) has to be done twice, to lose the selection. In the console log you can see the message "Update NavigationAuthority bound path tried to update multiple times per frame." appearing. Not sure if this has something todo with the selection being lost. This is on iOS 16.4.1 not sure if the behaviour before was different. Anybody experiences the same behaviour? Bug in SwiftUI or in the sample app? Cheers, Michael
2
1
948
Apr ’23
Curious sheet behaviour
Hi, I have a strange case involving sheets, which I think it's a bug, but then again I might be missing something. Using the following code: import SwiftUI enum WhichSheet: String { 	case one, two, three, none } struct ContentView: View { 	@State private var _showSheet = false 	@State private var _whichSheet: WhichSheet = .none 		var body: some View { 			VStack(spacing: 8) { 					Button("One Sheet", action: { self._whichSheet = .one; self._showSheet = true}) 					Button("Two Sheet", action: { self._whichSheet = .two; self._showSheet = true}) 					Button("Three Sheet", action: { self._whichSheet = .three; self._showSheet = true}) 			} 				.sheet(isPresented: $_showSheet, content: { 				Text("whichSheet = \(_whichSheet.rawValue)") 			}) 		} } struct ContentView_Previews: PreviewProvider { 		static var previews: some View { 			ContentView() 		} } I would assume that, depending on which button is pressed, I would say a sheet with the text "whichSheet = one" or "whichSheet = two" etc. But no matter which button is pressed first the text on the sheet is always "whichSheet = none". Only if you choose a different button the second (or third, or ...) time the correct text is being displayed. Bug or am I missing something really obvious? (Test using an iOS 14 / 14.2 project with Xcode 12 / 12.2 beta) Cheers, Michael
4
0
1.8k
Mar ’22
Using actors in a SwiftUI .task
Hi, having the concurrency checks (-Xfrontend -warn-concurrency -Xfrontend -enable-actor-data-race-checks-Xfrontend -warn-concurrency -Xfrontend -enable-actor-data-race-checks) enabled I always get this warning, when trying to access/use an actor in a SwiftUI .task: "Cannot use parameter 'self' with a non-sendable type 'ContentView' from concurrently-executed code". What would be a correct implementation? Here's a minimal code-sample which produces this warning: import SwiftUI struct ContentView: View { @State var someVar = 5 var a1 = A1() var body: some View { Text("Hello, world!") .padding() .task { await a1.doSomething() } } } public actor A1 { func doSomething() { print("Hello") } }
1
0
2.3k
Feb ’22
Do I need to add my own unique id?
Hi, if I have a @Model class there's always an id: PersistentIdentifier.ID underneath which, according to the current documentation "The value that uniquely identifies the associated model within the containing store.". So I am wondering if it is (good) enough to rely on this attribute to uniquely identify @Model class entities, or if there are edge cases where it does not work (like maybe when using CloudKit)? If anybody saw some information regarding this, please let me know :-) Cheers, Michael
5
3
3.1k
Aug ’24
No "upsert" when working with .unique attributes
Hi, in the session the following is mentioned: If a trip already exists with that name, then the persistent back end will update to the latest values. This is called an upsert. An upsert starts as an insert. If the insert collides with existing data, it becomes an update and updates the properties of the existing data. Nevertheless, if I have a unique constraint on an (String) attribute and try to insert the same again, I end up in the debugger in the generated getter of the attribute: @Attribute(.unique) public var name: String { get { _$observationRegistrar.access(self, keyPath: \.name) return self.getValue(for: \.name) // <- here } EXC_BREAKPOINT (code=1, subcode=0x1a8d6b724) Am I missing something? If this is expected behaviour, how should I prevent this crash (other than checking for uniqueness before every insert)? Thank you! Cheers, Michael
4
5
2.7k
Aug ’23
Crashes in _os_semaphore_dispose.cold since Xcode 13 beta 5
Hi, since the Xcode 13 beta 5 I am seeing crashes in _os_semaphore_dispose.cold.* when running in the iOS simulator. This happens in different apps under various conditions, so I can pin it down to something specific. Is anybody else having similar issues? Stack of the crashing thread looks like this: Disassembly looks like this: Thanks for any feedback. Cheers, Michael
17
0
3.9k
Aug ’21