Skip to content

Commit eb220dd

Browse files
committed
implement attributes mutating methods
1 parent 3206f9d commit eb220dd

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Foundation/NSAttributedString.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,10 @@ extension NSAttributedString {
307307
open class NSMutableAttributedString : NSAttributedString {
308308

309309
open func replaceCharacters(in range: NSRange, with str: String) { NSUnimplemented() }
310-
open func setAttributes(_ attrs: [NSAttributedStringKey : Any]?, range: NSRange) { NSUnimplemented() }
310+
311+
open func setAttributes(_ attrs: [NSAttributedStringKey : Any]?, range: NSRange) {
312+
CFAttributedStringSetAttributes(_cfMutableObject, CFRange(range), attrs?._cfObject, true)
313+
}
311314

312315
open var mutableString: NSMutableString {
313316
return _string as! NSMutableString
@@ -317,9 +320,13 @@ open class NSMutableAttributedString : NSAttributedString {
317320
CFAttributedStringSetAttribute(_cfMutableObject, CFRange(range), name.rawValue._cfObject, _SwiftValue.store(value))
318321
}
319322

320-
open func addAttributes(_ attrs: [NSAttributedStringKey : Any], range: NSRange) { NSUnimplemented() }
323+
open func addAttributes(_ attrs: [NSAttributedStringKey : Any], range: NSRange) {
324+
CFAttributedStringSetAttributes(_cfMutableObject, CFRange(range), attrs._cfObject, false)
325+
}
321326

322-
open func removeAttribute(_ name: NSAttributedStringKey, range: NSRange) { NSUnimplemented() }
327+
open func removeAttribute(_ name: NSAttributedStringKey, range: NSRange) {
328+
CFAttributedStringRemoveAttribute(_cfMutableObject, CFRange(range), name.rawValue._cfObject)
329+
}
323330

324331
open func replaceCharacters(in range: NSRange, with attrString: NSAttributedString) { NSUnimplemented() }
325332
open func insert(_ attrString: NSAttributedString, at loc: Int) { NSUnimplemented() }

0 commit comments

Comments
 (0)