Skip to content

Commit 22654b0

Browse files
committedDec 24, 2017
implement more methods by mapping CFAttributedString functions calls
1 parent db3aeaa commit 22654b0

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed
 

‎Foundation/NSAttributedString.swift

+31-8
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,9 @@ extension NSAttributedString {
306306

307307
open class NSMutableAttributedString : NSAttributedString {
308308

309-
open func replaceCharacters(in range: NSRange, with str: String) { NSUnimplemented() }
309+
open func replaceCharacters(in range: NSRange, with str: String) {
310+
CFAttributedStringReplaceString(_cfMutableObject, CFRange(range), str._cfObject)
311+
}
310312

311313
open func setAttributes(_ attrs: [NSAttributedStringKey : Any]?, range: NSRange) {
312314
guard let attrs = attrs else {
@@ -332,14 +334,35 @@ open class NSMutableAttributedString : NSAttributedString {
332334
CFAttributedStringRemoveAttribute(_cfMutableObject, CFRange(range), name.rawValue._cfObject)
333335
}
334336

335-
open func replaceCharacters(in range: NSRange, with attrString: NSAttributedString) { NSUnimplemented() }
336-
open func insert(_ attrString: NSAttributedString, at loc: Int) { NSUnimplemented() }
337-
open func append(_ attrString: NSAttributedString) { NSUnimplemented() }
338-
open func deleteCharacters(in range: NSRange) { NSUnimplemented() }
339-
open func setAttributedString(_ attrString: NSAttributedString) { NSUnimplemented() }
337+
open func replaceCharacters(in range: NSRange, with attrString: NSAttributedString) {
338+
CFAttributedStringReplaceAttributedString(_cfMutableObject, CFRange(range), attrString._cfObject)
339+
}
340+
341+
open func insert(_ attrString: NSAttributedString, at loc: Int) {
342+
NSUnimplemented()
343+
}
344+
345+
open func append(_ attrString: NSAttributedString) {
346+
NSUnimplemented()
347+
}
348+
349+
open func deleteCharacters(in range: NSRange) {
350+
// To delete a range of the attributed string, call CFAttributedStringReplaceString() with empty string and specified range
351+
let emptyString = ""._cfObject
352+
CFAttributedStringReplaceString(_cfMutableObject, CFRange(range), emptyString)
353+
}
354+
355+
open func setAttributedString(_ attrString: NSAttributedString) {
356+
NSUnimplemented()
357+
}
358+
359+
open func beginEditing() {
360+
CFAttributedStringBeginEditing(_cfMutableObject)
361+
}
340362

341-
open func beginEditing() { NSUnimplemented() }
342-
open func endEditing() { NSUnimplemented() }
363+
open func endEditing() {
364+
CFAttributedStringEndEditing(_cfMutableObject)
365+
}
343366

344367
public override init(string str: String) {
345368
super.init(string: str)

0 commit comments

Comments
 (0)
Please sign in to comment.