如何停止枚举NSAttributedString的属性? [英] How to stop enumerating attributes of a NSAttributedString?
本文介绍了如何停止枚举NSAttributedString的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 enumerateAttribute
方法的文档中,关于该块的 stop
参数,有人说:
In the documentation of the enumerateAttribute
method it is said, regarding the stop
argument of the block, that:
该块可以将值设置为true以停止对该集合的进一步处理。
The block can set the value to true to stop further processing of the set.
但是,在块内的 stop
参数是 let
,而我不能将其设置为 true
。
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
}
请参见参考 UnsafeMutablePointer 。
这篇关于如何停止枚举NSAttributedString的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文