在 enumerateAttribute
方法的文档中,关于 block 的 stop
参数,是这样说的:
The block can set the value to true to stop further processing of the set.
但是,在 block 内,stop
参数是一个 let
,我无法将它设置为 true
。
我需要在找到第一个属性出现后停止枚举。我怎么能那样做?
最佳答案
参数是保存实际值的引用:
let attributed: NSAttributedString = ...
attributed.enumerateAttribute(
NSFontAttributeName,
in: NSRange(location: 0, length: attributed.length),
options: []
) { value, range, stop in
stop.pointee = true
}
参见 UnsafeMutablePointer 的引用资料.
关于ios - 如何停止枚举 NSAttributedString 的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41547030/