Skip to content

Instantly share code, notes, and snippets.

@krzyzanowskim
Last active August 5, 2023 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krzyzanowskim/1c07715c5193382562b2e597379a8e4b to your computer and use it in GitHub Desktop.
Save krzyzanowskim/1c07715c5193382562b2e597379a8e4b to your computer and use it in GitHub Desktop.
FB12863947
// Documentation says:
//
// > Executes the specified block for each range of a particular attribute in the attributed string.
//
// documentation is not correct (or implementation, hard to tell). The block is executed at least once, not matter if particular attribute is or is not present in the attributed string.
import Foundation
import AppKit
/// Attributed string without any attribute, in particular no font attribute set
let attr = NSAttributedString(string: "foo")
/// Executes the specified closure for each range of a particular attribute in the attributed string.
attr.enumerateAttribute(.font, in: NSRange(location: 0, length: attr.length)) { value, range, stop in
// how many times executed?
print(range)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment