Post

Replies

Boosts

Views

Activity

What is `ViewModifier.Content`?
If you look at the documentation - https://developer.apple.com/documentation/swiftui/viewmodifier/content, it is just declared as a typealias. I somewhat expected it to be a generic argument on the modifier. What is the underlying type and how does Swift know it is a View?
1
0
502
Jun ’20
View disappearing, then reappearing when following a navigation link
I'm seeing some unexpected behavior when pushing a view using NavigationLink. It seems the source view momentarily disappears, the reappears when pushing the destination view, finally disappearing for good after the transition has completed. You can notice the following output if you use the code below it in a brand new iOS project (from the default Xcode template), run it, and tap on the navigation link. Is this expected behavior? Source appear Source disappear Source appear Destination appear Source disappear struct ContentView: View { 	var body: some View { 		NavigationView { 			VStack { 				Text("Hello, world!").padding() 					.onAppear { 						print("Source appear") 					} 					.onDisappear { 						print("Source disappear") 					} 				NavigationLink( 					destination: DestinationView(), 					label: { 						Text("Navigate") 					}) 			} 		} 	} } struct DestinationView: View { 	var body: some View { 		Text("Destination View") 			.onAppear { 				print("Destination appear") 			} 			.onDisappear { 				print("Destination disappear") 			} 	} }
0
1
831
Jul ’20
XPC Service not working in packaged app
I'm trying to use XPC communicate between a command line tool (launched from Terminal) and a macOS application. My code currently works when the app is launched from Xcode, but not if I launch the built app from the command line (open path-to-foo.app) or if I try and distribute the packaged application (via "Development" distribution). Notably, the XPC works if the command line tool is launched from the terminal as long as the app itself is launched from Xcode. I publish the XPC service using NSXPCListener(machServiceName: <team-identifier>.com.example.my-app.service) and connect to it using NSXPCConnection(machServiceName: machServiceName). Both my command line tool and my main app identical "app group" entitlements for $(TeamIdentifierPrefix)com.example.my-app and I verified the team identifier substitution was correct in both the app and command line tool after doing distributing for "App Store", exporting, unpacking the pkg and running codesign as described here: https://developer.apple.com/documentation/xcode/embedding-a-helper-tool-in-a-sandboxed-app
1
0
631
Jul ’24
Swift Data issue when property implements custom Codable conformance.
I have a type which represents an ID. This ID comes from a backend as an untyped string. The Swift type looks something like this: struct TypedID: Codable { init(_ string: String) { stringValue = string } init(from decoder: any Decoder) throws { stringValue = try decoder.singleValueContainer().decode(String.self) } func encode(to encoder: any Encoder) throws { try stringValue.encode(to: encoder) } let stringValue: String } If I use this type in a SwiftData @Model, or even as a property of another Codeable struct which is contained in the @Model, SwiftData fails to create instances of my model and emits the following error: CoreData: error: CoreData: error: Row (pk = #) for entity '<@Model type>' is missing mandatory text data for property 'stringValue' This issue goes away if I remove the custom implementation of init(from:) and encode(to:), but doing so makes the coded representation of my type an object instead of a string, which is not what I want. /// JSON without custom implementations: { "stringValue": "<the ID>" } /// JSON with custom implementations: "<the ID>" Is there anything I can do to be able to serialize a Codable type with a custom coding implementation like this to a SwiftData model?
3
0
452
Sep ’24
Virtualization Framework with programmatic keyboard / pointing device.
I'm curious if there is a way to add a programmatically controlled keyboard and pointing device to a virtual machine created using Virtualization.framework (for the purposes of sandboxed automation). All of the types I've found in that framework have very little in the way of configurability and seem to be uniquely intended for use with a VZVirtualMachineView. On the other hand, Hypervisor.framework seems extremely low-level so I'm wondering if there is something in between the two I can use to achieve this.
0
0
95
5d