Created
September 4, 2023 16:09
-
-
Save daltonclaybrook/5491f296d9d5806dd31f4d777aea347f to your computer and use it in GitHub Desktop.
An example unwrapping a (Date, Text.DateStyle) from LocalizedStringKey underlying storage. I'm not sure how to actually format the date with the DateStyle.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOS 8.0, *) | |
private func stringFromDateStyle(storage: Any) -> String? { | |
let dateStyleChildren = Array(Mirror(reflecting: storage).children) | |
guard dateStyleChildren.count == 2, let text = dateStyleChildren[0].value as? Text else { | |
return nil | |
} | |
let textStorage = Array(Mirror(reflecting: text).children)[0].value // Text.Storage | |
let dateTextStorage = Array(Mirror(reflecting: textStorage).children)[0].value | |
guard "\(type(of: dateTextStorage))" == "DateTextStorage" else { | |
return nil | |
} | |
guard let (date, dateStyle) = Array(Mirror(reflecting: Array(Mirror(reflecting: dateTextStorage).children)[0].value).children)[0].value as? (Date, Text.DateStyle) else { | |
return nil | |
} | |
return "???" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment