Therefore when a search string that doesn't exist in the attributed string is searched for, the function crashes.
Here's a test that re-creates this issue:
context("when the search string does not exist in the attributed string") {
it("cannot find the string") {
let redForegroundColor = [NSAttributedString.Key.foregroundColor : UIColor.red]
let mutableAttributedString = NSMutableAttributedStringBuilder(withText: "Foreground and Background")
.withAttributes(
redForegroundColor,
range: NSRange(location: 0, length: 10)
)
.build()
let attributedString = mutableAttributedString.copy() as! NSAttributedString
expect(attributedString.containsExactString("Invalid", withAttributes: redForegroundColor)).to(beTrue())
}
}
Can you add this test and adjust the code to make it pass? Thanks!
There's a forced unwrapped optional when looking for the search string in an attributed string:
https://github.com/derekleerock/Succinct/blob/413cda993cbbe6011feec8cdb7a6edf1939a9436/Succinct/NSAttributedString/NSAttributedString%2Battributes.swift#L13
Therefore when a search string that doesn't exist in the attributed string is searched for, the function crashes.
Here's a test that re-creates this issue:
Can you add this test and adjust the code to make it pass? Thanks!