WTF. How is UUID not one of the types you can store in @SceneStorage? And worse, how come the limited types usable aren't documented*? #Swift #SwiftUI

*I've searched the pages for SceneStorage, AppStorage, and “Restoring your app's state with SwiftUI" and haven't found mention of data type restrictions.

I scrutinized the “Restoring your app's state with SwiftUI" page and found this one sentence buried innocuously in a dense paragraph: “The value is required to be of a plist type, so the system can save and restore it correctly.”

https://developer.apple.com/documentation/swiftui/restoring-your-app-s-state-with-swiftui

Nowhere does it list what “plist type” contains, nor does it link to a definition. After manually searching for plist types I found the “Information Property List" page on Apple's documentation site, which also does not provide any useful information about supported data types.

https://developer.apple.com/documentation/bundleresources/information-property-list

#Swift #SwiftUI

Restoring your app’s state with SwiftUI | Apple Developer Documentation

Provide app continuity for users by preserving their current activities.

Apple Developer Documentation

@gregatron5 an approximation of them is listed on the UserDefaults page:

"The defaults database supports the same value types found in property list files, including types like Int, Float, Double, Bool, String, URL, NSNumber, Date, Array, and Dictionary. To include other types of objects in the defaults database, archive them to a Data object first and store that object instead.”

https://developer.apple.com/documentation/foundation/userdefaults

UserDefaults | Apple Developer Documentation

An interface to the user’s defaults database, which stores system-wide and app-specific settings.

Apple Developer Documentation
@amyworrall ”man plist” in Terminal or developer.apple.com/library/a… gives you a list of CF types that map quite readily to Swift types
Introduction to Property List Programming Topics for Core Foundation

Explains how to use structured, textual representations of data in Core Foundation.

@gregatron5 this is old-school Cocoa stuff. There is an old document listing the types here: https://developer.apple.com/library/archive/documentation/General/Conceptual/DevPedia-CocoaCore/PropertyList.html

I can't imagine why a current/new Swift API would depend on plist types, rather than Codable conformance, though.

Property list

A collection of short articles on the core concepts, patterns, and mechanisms in Cocoa programming.

@mbessey @gregatron5 Binary PLISTs are more compact than JSON. That could be a factor? Potentially there is some CF era API they need here for some reason that requires PLIST?

@vanvoorden @mbessey Looks like someone was lazy. According to WIkipedia the binary plist format supports UUIDs but the XML version does not. I suppose SceneStorage inherited the worst of both worlds.

https://en.wikipedia.org/wiki/Property_list

Property list - Wikipedia

@gregatron5 @mbessey Right… if the infra wants binary PLIST for smaller size *plus* xml bridging after the binary is decoded that could be where the restrictions are coming from.
@mbessey @gregatron5 I think PLIST might also have easier bridging to XML. There could be some XML parsing logic happing inside that makes PLIST the better choice?

@gregatron5 Oh it's somewhere in the documentation archives, which I don't think show up on searches anymore unless you really know what you're looking for.

Ints and Double, String, Bool —a lot of weirdness with those for historical reasons—, Data, plus arrays and string-keyed dictionaries of plist types (includes multi-level collections). Not sure if I'm forgetting something but that's about it.