@@ -48,15 +48,17 @@ open class NSAttributedString: NSObject, NSCopying, NSMutableCopying, NSSecureCo
48
48
}
49
49
50
50
open func copy( with zone: NSZone ? = nil ) -> Any {
51
- NSUnimplemented ( )
51
+ return self
52
52
}
53
53
54
54
open override func mutableCopy( ) -> Any {
55
55
return mutableCopy ( with: nil )
56
56
}
57
57
58
58
open func mutableCopy( with zone: NSZone ? = nil ) -> Any {
59
- NSUnimplemented ( )
59
+ let mutableAttrString = NSMutableAttributedString ( string: " " )
60
+ mutableAttrString. setAttributedString ( self )
61
+ return mutableAttrString
60
62
}
61
63
62
64
/// The character contents of the receiver as an NSString object.
@@ -112,7 +114,9 @@ open class NSAttributedString: NSObject, NSCopying, NSMutableCopying, NSSecureCo
112
114
}
113
115
114
116
/// Returns a Boolean value that indicates whether the receiver is equal to another given attributed string.
115
- open func isEqual( to other: NSAttributedString ) -> Bool { NSUnimplemented ( ) }
117
+ open func isEqual( to other: NSAttributedString ) -> Bool {
118
+ return CFEqual ( _cfObject, other. _cfObject)
119
+ }
116
120
117
121
/// Returns an NSAttributedString object initialized with the characters of a given string and no attribute information.
118
122
public init ( string: String ) {
@@ -134,7 +138,9 @@ open class NSAttributedString: NSObject, NSCopying, NSMutableCopying, NSSecureCo
134
138
135
139
/// Returns an NSAttributedString object initialized with the characters and attributes of another given attributed string.
136
140
public init ( attributedString: NSAttributedString ) {
137
- NSUnimplemented ( )
141
+ let mutableCopy = attributedString. mutableCopy ( ) as! NSMutableAttributedString
142
+ _string = mutableCopy. _string
143
+ _attributeArray = mutableCopy. _attributeArray
138
144
}
139
145
140
146
/// Executes the block for each attribute in the range.
@@ -358,7 +364,8 @@ open class NSMutableAttributedString : NSAttributedString {
358
364
}
359
365
360
366
open func setAttributedString( _ attrString: NSAttributedString ) {
361
- NSUnimplemented ( )
367
+ let fullStringRange = NSRange ( location: 0 , length: length)
368
+ replaceCharacters ( in: fullStringRange, with: attrString)
362
369
}
363
370
364
371
open func beginEditing( ) {
@@ -369,6 +376,10 @@ open class NSMutableAttributedString : NSAttributedString {
369
376
CFAttributedStringEndEditing ( _cfMutableObject)
370
377
}
371
378
379
+ open override func copy( with zone: NSZone ? = nil ) -> Any {
380
+ return NSAttributedString ( attributedString: self )
381
+ }
382
+
372
383
public override init ( string str: String ) {
373
384
super. init ( string: str)
374
385
_string = NSMutableString ( string: str)
0 commit comments