ios - 如何停止枚举 NSAttributedString 的属性?

标签 ios swift nsattributedstring enumeration

enumerateAttribute 方法的文档中,关于 block 的 stop 参数,是这样说的:

The block can set the value to true to stop further processing of the set.

但是,在 block 内,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 的引用资料.

关于ios - 如何停止枚举 NSAttributedString 的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41547030/

相关文章:

ios - Xcode 中的 Control-drag 提供了 socket ,但没有对 UIButton 的操作。为什么?

ios - NSAttributedString 与已经在字符串中的 css 脚本作斗争

ios - 如何使用 NSAttributedString objective-c 为字符串的一部分加下划线

ios - 如何解决 fatal error : unexpectedly found nil while unwrapping an Optional value

swift - UILabel 原来是圆形的,现在变成了椭圆形

ios - 如何让iOS UIWebView正确显示手机网站?

ios - 加密 key : Can I use obfuscation?

ios - 带有属性字符串的电子邮件编辑器

objective-c - 移除 UITableView 中的编辑按钮

iphone - AVAudioSession类别无法按文档要求运行