2017-01-09 79 views
1

在它被称enumerateAttribute方法的文档,关于块的stop论点,即:如何停止枚举NSAttributedString的属性?

块可以将该值设置为true,停止集的进一步处理。

然而,块内的stop参数是一个let,我不能将其设置为true

我需要在发现第一个属性发生后停止枚举。我怎么能这样做?

+0

密切相关:http://stackoverflow.com/questions/24214136/how-to-stop-enumerateobjectsusingblock-swift。 –

回答

4

的参数是保存实际值的参考:

let attributed: NSAttributedString = ... 

attributed.enumerateAttribute(
    NSFontAttributeName, 
    in: NSRange(location: 0, length: attributed.length), 
    options: [] 
) { value, range, stop in 
    stop.pointee = true 
} 

参见UnsafeMutablePointer参考。