Skip to content

Instantly share code, notes, and snippets.

@chockenberry
Last active October 10, 2022 21:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chockenberry/5916dc25d4ff12d6a376a661558fc721 to your computer and use it in GitHub Desktop.
Save chockenberry/5916dc25d4ff12d6a376a661558fc721 to your computer and use it in GitHub Desktop.
import Foundation
let okString = "WTF\r\nHELLO"
let wtfString = AttributedString(okString)
if let lineRange = okString.range(of: "\n") {
let lineSubstring = okString[okString.startIndex..<lineRange.lowerBound]
type(of: lineSubstring)
lineSubstring.count
}
if let lineRange = wtfString.range(of: "\n") {
let lineSubstring = wtfString[wtfString.startIndex..<lineRange.lowerBound]
type(of: lineSubstring.characters)
lineSubstring.characters.first!
lineSubstring.characters.last!
lineSubstring.characters.count // BOOM
// same with lineSubstring.characters.underestimatedCount
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment