How to stop enumerating attributes of a NSAttributedString?

佐手、 提交于 2019-12-01 17:48:25

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/41547030/how-to-stop-enumerating-attributes-of-a-nsattributedstring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!