NSMutableAttributedString initialisation to prevent crash

Apple Recommended

  • is this issue fixed now or still happened ?

  • still happens

  • Still happening here. In my case, I have CoreData hooked up to a UITableView, so the crash was the infamous Invalid update: invalid number of sections. The number of sections contained in the table view after the update (2) must be equal to the number of sections contained in the table view before the update (2), plus or minus the number of sections inserted or deleted (1 inserted, 0 deleted). For some reason, the CoreData transaction would be finished at the wrong time, causing the crash. You can imagine how many hours I spent on it...

Replies

Do you have a hint of what could be going wrong here?

No, sorry.

Can you isolate this into a small test project? If so, you could try opening a DTS tech support incident to see if someone is up for digging into this. It’s possible that your library is doing something wrong and that’s triggering this problem. OTOH, it’s also possible that both your code and your client’s code are just an innocent bystanders.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

What do you mean?

This was discussed in WWDC 2021 Session 10109 What’s new in Foundation. As the session title suggests, it’s not limited to SwiftUI.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Facing same issue in ios 15.2.1. Is this issue resolve?

Still happening here

Sadly, that’s expected. I’ve updated my response with more details and marked it as Apple Recommended.

Speaking personally, I wouldn’t build an app that relies on this feature. This bug has been around for years now — many more years than this thread, and it’s already 3 years old!

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I am trying to convert HTML to attributed string so used this try NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding: String.Encoding.utf8.rawValue], documentAttributes: nil)

But, am getting memory leak in this single line and due to memory leak app crashes.. Any solution for this??