Exceeding max Text(“”) concatenation length - SwiftUI -

前端 未结 2 1802
后悔当初
后悔当初 2020-12-21 06:14

With reference to the answer posted by Asperi (https://stackoverflow.com/users/12299030/asperi) on Question: Highlight a specific part of the text in SwiftUI

I have f

2条回答
  •  不思量自难忘°
    2020-12-21 06:52

    Hmm... unexpected limitation... anyway - learn something new.

    Ok, here is improved algorithm, which should move that limitation far away.

    Tested with Xcode 12 / iOS 14. (also updated code in referenced topic Highlight a specific part of the text in SwiftUI)

    func hilightedText(str: String, searched: String) -> Text {
        guard !str.isEmpty && !searched.isEmpty else { return Text(str) }
    
        var result = Text("")
    
        var range = str.startIndex..

提交回复
热议问题