Skip to content

Commit cd25320

Browse files
committed
NSAttributedString: Minor fixes
1 parent d3b6dcb commit cd25320

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

Foundation/NSAttributedString.swift

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ open class NSAttributedString: NSObject, NSCopying, NSMutableCopying, NSSecureCo
6565
}
6666

6767
/// Returns the attributes for the character at a given index.
68-
open func attributes(at location: Int, effectiveRange range: NSRangePointer) -> [NSAttributedStringKey : Any] {
68+
open func attributes(at location: Int, effectiveRange range: NSRangePointer?) -> [NSAttributedStringKey : Any] {
6969
let rangeInfo = RangeInfo(
7070
rangePointer: range,
7171
shouldFetchLongestEffectiveRange: false,
@@ -278,16 +278,11 @@ private extension NSAttributedString {
278278
}
279279

280280
let range = CFRange(location: 0, length: _string.length)
281+
var attributes: [String : Any] = [:]
281282
if let attrs = attrs {
282-
var _attrs: [String: Any] = [:]
283-
for (key, value) in attrs {
284-
_attrs[key.rawValue] = value
285-
}
286-
CFRunArrayInsert(_attributeArray, range, _attrs._cfObject)
287-
} else {
288-
let emptyAttrs = [String : AnyObject]()
289-
CFRunArrayInsert(_attributeArray, range, emptyAttrs._cfObject)
283+
attrs.forEach { attributes[$0.rawValue] = $1 }
290284
}
285+
CFRunArrayInsert(_attributeArray, range, attributes._cfObject)
291286
}
292287
}
293288

0 commit comments

Comments
 (0)