pointfreeco / swift-composable-architecture

A library for building applications in a consistent and understandable way, with composition, testing, and ergonomics in mind.
https://www.pointfree.co/collections/composable-architecture
MIT License
12.35k stars 1.44k forks source link

NSAttributedString property occurs crash #2316

Closed artemkrachulov closed 1 year ago

artemkrachulov commented 1 year ago

Description

In our project we have to use the bindable NSAttributedString property:

struct State: Equatable {

    /// Text bound with text area
    @BindingState public var text: String

     /// Attributed text bound with text area
    @BindingState public var attributedString: NSAttributedString?
    ...
}

I've added it. Two or three times I could navigate to the specific screen where this state was. Then crash appears:

Screenshot 2023-07-21 at 5 16 44 PM

When I remove @BindingState property wrapper I have another crash:

Screenshot 2023-07-21 at 5 22 41 PM

8 of 10 times it crashes. So the crash is not 100% permanent. Also, I couldn't reproduce it in the clear project, this is very strange.

Checklist

Expected behavior

No response

Actual behavior

No response

Steps to reproduce

No response

The Composable Architecture version information

0.55.0

Destination operating system

16.5.1

Xcode version information

Version 14.3.1 (14E300c)

Swift Compiler version information

swift-driver version: 1.75.2 Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)
Target: x86_64-apple-macosx13.0
stephencelis commented 1 year ago

@artemkrachulov Without a project to work with I'm not sure there's much we can do here, so I'm going to convert to a discussion till it can be determined that this is a library bug.

I will note that I notice a couple strange things in the code above:

  1. Why are you making NSAttributedString a @BindingState? I'm not aware of a SwiftUI control that takes a binding to an NSAttributedString.
  2. I'm not sure NSAttributedString is safe to hold in app state in general. TCA state is meant to hold value types, but NSAttributedString is a class.

Does the crash go away entirely if you remove NSAttributedString from state and use a plain String (or AttributedString) instead?