Skip to content

Commit 3659545

Browse files
committed
Use CoreFoundation methods when possible
1 parent 864d2bb commit 3659545

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Foundation/NSAttributedString.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import CoreFoundation
1212
public class NSAttributedString : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
1313

1414
private let _cfinfo = _CFInfo(typeID: CFAttributedStringGetTypeID())
15-
private let _string: String
15+
private let _string: NSString
1616
private let _attributeArray: CFRunArrayRef
1717

1818
public required init?(coder aDecoder: NSCoder) {
@@ -44,14 +44,14 @@ public class NSAttributedString : NSObject, NSCopying, NSMutableCopying, NSSecur
4444
}
4545

4646
public var string: String {
47-
return _string
47+
return _string._swiftObject
4848
}
4949

5050
public func attributesAtIndex(_ location: Int, effectiveRange range: NSRangePointer) -> [String : AnyObject] {
51-
var cfRange = CFRange(location: NSNotFound, length: 0)
51+
var cfRange = CFRange()
5252
return withUnsafeMutablePointer(&cfRange) { (rangePointer: UnsafeMutablePointer<CFRange>) -> [String : AnyObject] in
5353
// Get attributes value from `_attributeArray`
54-
let value = CFRunArrayGetValueAtIndex(_attributeArray, location, rangePointer, nil).takeUnretainedValue()
54+
let value = CFAttributedStringGetAttributes(_cfObject, location, rangePointer)
5555

5656
// Convert the value to [String : AnyObject]
5757
let dictionary = unsafeBitCast(value, to: NSDictionary.self)
@@ -73,7 +73,7 @@ public class NSAttributedString : NSObject, NSCopying, NSMutableCopying, NSSecur
7373
}
7474

7575
public var length: Int {
76-
return _string.length
76+
return CFAttributedStringGetLength(_cfObject)
7777
}
7878

7979
public func attribute(_ attrName: String, atIndex location: Int, effectiveRange range: NSRangePointer) -> AnyObject? { NSUnimplemented() }
@@ -85,15 +85,15 @@ public class NSAttributedString : NSObject, NSCopying, NSMutableCopying, NSSecur
8585
public func isEqualToAttributedString(_ other: NSAttributedString) -> Bool { NSUnimplemented() }
8686

8787
public init(string str: String) {
88-
_string = str
88+
_string = str._nsObject
8989
_attributeArray = CFRunArrayCreate(kCFAllocatorDefault)
9090

9191
super.init()
9292
addAttributesToAttributeArray(attrs: nil)
9393
}
9494

9595
public init(string str: String, attributes attrs: [String : AnyObject]?) {
96-
_string = str
96+
_string = str._nsObject
9797
_attributeArray = CFRunArrayCreate(kCFAllocatorDefault)
9898

9999
super.init()

0 commit comments

Comments
 (0)