如何停止枚举 NSAttributedString 的属性?
How to stop enumerating attributes of a NSAttributedString?
在 enumerateAttribute
方法的文档中说,关于块的 stop
参数,即:
The block can set the value to true to stop further processing of the set.
但是,在块内,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 的参考。
在 enumerateAttribute
方法的文档中说,关于块的 stop
参数,即:
The block can set the value to true to stop further processing of the set.
但是,在块内,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 的参考。