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。 –