简体   繁体   中英

How to stop enumerating attributes of a NSAttributedString?

In the documentation of the enumerateAttribute method it is said, regarding the stop argument of the block, that:

The block can set the value to true to stop further processing of the set.

However, inside the block the stop argument is a let and I can't set it to true .

I need to stop enumerating after the first attribute occurrence found. How could I do that?

The parameter is a reference that holds the actual value:

let attributed: NSAttributedString = ...

attributed.enumerateAttribute(
    NSFontAttributeName,
    in: NSRange(location: 0, length: attributed.length),
    options: []
) { value, range, stop in
    stop.pointee = true
}

See the reference for UnsafeMutablePointer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM