Skip to content

Instantly share code, notes, and snippets.

@jemmons
Created December 22, 2015 21:06
Show Gist options
  • Save jemmons/cc5240858590566436ac to your computer and use it in GitHub Desktop.
Save jemmons/cc5240858590566436ac to your computer and use it in GitHub Desktop.
import UIKit
let attr = NSAttributedString(string: "Hello, playground", attributes: [NSBackgroundColorAttributeName:UIColor.redColor()])
var shouldBeOne = 1
attr.enumerateAttribute(NSBackgroundColorAttributeName, inRange: NSMakeRange(0, attr.length), options:[]) { (value, range, stop) -> Void in
shouldBeOne += 1
}
print(shouldBeOne) //<- prints "1"
var shouldBeZero = 0
attr.enumerateAttribute("not a real attribute", inRange: NSMakeRange(0, attr.length), options:[]) { (value, range, stop) -> Void in
shouldBeZero += 1
}
print(shouldBeZero) //<- prints "1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment