UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

print() Crashes with @Binding<NSAttributedString>

Forums > SwiftUI

I am not sure if this should be here or in Swift forum. But I am using SwiftIUI and that is where I am seeing it.

I am looking for confirmation of a problem before I file a bug report with Apple.

I am on XCode Version 12.3 (12C33), on Big Sur (beta). It appears this update of XCode has a bug when using dianostic print statements that contain Bindings of NSAttributedStrings.

I am totally new to NSAttributedString and I am incorporating that into an NSRepresentable NSTextView for formatted text editing. So, being able to print is crucial to understanding what I am doing.

Could someone at the current level of release (same as I am) verify they can (or can't) print a @Binding<NSAttrributedString>, I would appreciate it.

Simple test:

struct ARepresentableView: NSViewRepresentable {

    @Binding var aString: NSAttributedString?

    func updateNSView(_ view: AnNSView, context: Context) {
        print("updateNSView: [\(aString)]")
        view.aStr = aString
    }

This works with the passed in value of aString. When the value of aString is changed within ARepresentableView, and the udpateNSView is called to refresh it the print state crashes with this:

2020-12-15 09:32:52.030427-0500 Hermes[77309:1627758] [General] *** -[NSBigMutableString substringWithRange:]: Range {27, 49} out of bounds; string length 60

2      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.