1
在它被称enumerateAttribute
方法的文档,关于块的stop
论点,即:如何停止枚举NSAttributedString的属性?
块可以将该值设置为true,停止集的进一步处理。
然而,块内的stop
参数是一个let
,我不能将其设置为true
。
我需要在发现第一个属性发生后停止枚举。我怎么能这样做?
在它被称enumerateAttribute
方法的文档,关于块的stop
论点,即:如何停止枚举NSAttributedString的属性?
块可以将该值设置为true,停止集的进一步处理。
然而,块内的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参考。
密切相关:http://stackoverflow.com/questions/24214136/how-to-stop-enumerateobjectsusingblock-swift。 –