【发布时间】:2017-05-26 13:00:27
【问题描述】:
我正在尝试从属性字符串中获取属性。除非字符串为空,否则一切正常。看看:
let s = NSAttributedString(string: "", attributes: [NSForegroundColorAttributeName: UIColor.red])
let range = NSMakeRange(0, s.length)
let attrs = s.attributes(at: 0, longestEffectiveRange: nil, in: range)
为什么我在最后一行出现越界异常?
【问题讨论】:
-
它在 Objective-C 中也崩溃了。在
if s.string.isEmpty之前检查? -
@Larme 我就是这样解决这个问题的,但我想知道为什么会这样