2017-01-09 41 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參考。