Skip to content

Force casting fails if TextState has an unexpected storage #269

@myihsan

Description

@myihsan

Description

Array(Mirror(reflecting: children[0].value).children)[0].value as! (Any, Formatter?)

The force casting above fails if the TextState has an unexpected storage such as AttibutedString.

LocalizedStringKey conforms to Equatable but returns false for equivalent format strings. To account for this we reflect on it to extract and string-format its storage.

I have noticed this comment and understand that this workaround is required for LocalizedStringKey.
But LocalizedStringResource does not seem to require it, so I think supporting LocalizedStringResource might be another workaround.

Checklist

  • I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue or discussion.

Expected behavior

No crash, no matter what the the storage is.

Actual behavior

Crash if the storage is not (Any, Formatter?).

Steps to reproduce

  1. Create a TextState with AttibutedString: TextState("\(AttributedString())")
  2. Trigger LocalizedStringKey.formatted(locale:tableName:bundle:comment:) by initial a String or check the equability

SwiftUI Navigation version information

2.2.3

Destination operating system

iOS 18.2

Xcode version information

16.2 (16C5032a)

Swift Compiler version information

swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-macosx15.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions