@@ -66,49 +66,31 @@ extension NSAttributedString {
66
66
return attributedSubstring ( from: NSRange ( range) )
67
67
}
68
68
69
- #if swift(>=4.0)
70
- /**
71
- Returns the value for an attribute with a given name of the character at a given index, and by reference the range over which the attribute applies.
72
-
73
- - parameters:
74
- - attrName: The name of an attribute.
75
- - location: The index for which to return attributes. This value must not exceed the bounds of the receiver.
76
- - range:
77
- If non-nil:
78
- - If the named attribute exists at `location`, upon return `range` contains a range over which the named attribute’s value applies.
79
- - If the named attribute does not exist at `location`, upon return `range` contains the range over which the attribute does not exist.
80
-
81
- The range isn’t necessarily the maximum range covered by `attrName`, and its extent is implementation-dependent.
82
- If you need the maximum range, use attribute(_:at:longestEffectiveRange:in:). If you don't need this value, pass `nil`.
83
- */
84
- public func swiftyAttribute( _ attrName: NSAttributedStringKey , at location: Int , effectiveRange range: NSRangePointer ? = nil ) -> Attribute ? {
85
- if let attributeValue: Any = attribute ( attrName, at: location, effectiveRange: range) {
86
- return Attribute ( name: attrName, foundationValue: attributeValue)
87
- }
88
- return nil
89
- }
90
- #else
91
- /**
92
- Returns the value for an attribute with a given name of the character at a given index, and by reference the range over which the attribute applies.
93
-
94
- - parameters:
95
- - attrName: The name of an attribute.
96
- - location: The index for which to return attributes. This value must not exceed the bounds of the receiver.
97
- - range:
98
- If non-nil:
99
- - If the named attribute exists at `location`, upon return `range` contains a range over which the named attribute’s value applies.
100
- - If the named attribute does not exist at `location`, upon return `range` contains the range over which the attribute does not exist.
101
-
102
- The range isn’t necessarily the maximum range covered by `attrName`, and its extent is implementation-dependent.
103
- If you need the maximum range, use attribute(_:at:longestEffectiveRange:in:). If you don't need this value, pass `nil`.
104
- */
105
- public func attribute( _ attrName: AttributeName , at location: Int , effectiveRange range: NSRangePointer ? = nil ) -> Attribute ? {
106
- if let attributeValue = attribute ( attrName. rawValue, at: location, effectiveRange: range) {
107
- return Attribute ( name: attrName, foundationValue: attributeValue)
108
- }
109
- return nil
69
+ /**
70
+ Returns the value for an attribute with a given name of the character at a given index, and by reference the range over which the attribute applies.
71
+
72
+ - parameters:
73
+ - attrName: The name of an attribute.
74
+ - location: The index for which to return attributes. This value must not exceed the bounds of the receiver.
75
+ - range:
76
+ If non-nil:
77
+ - If the named attribute exists at `location`, upon return `range` contains a range over which the named attribute’s value applies.
78
+ - If the named attribute does not exist at `location`, upon return `range` contains the range over which the attribute does not exist.
79
+
80
+ The range isn’t necessarily the maximum range covered by `attrName`, and its extent is implementation-dependent.
81
+ If you need the maximum range, use attribute(_:at:longestEffectiveRange:in:). If you don't need this value, pass `nil`.
82
+ */
83
+ public func swiftyAttribute( _ attrName: AttributeName , at location: Int , effectiveRange range: NSRangePointer ? = nil ) -> Attribute ? {
84
+ #if swift(>=4.0)
85
+ let name = attrName
86
+ #else
87
+ let name = attrName. rawValue
88
+ #endif
89
+ if let attributeValue: Any = attribute ( name, at: location, effectiveRange: range) {
90
+ return Attribute ( name: attrName, foundationValue: attributeValue)
110
91
}
111
- #endif
92
+ return nil
93
+ }
112
94
113
95
/**
114
96
Returns the enumerated attributes in a specified range as an array of attribute-range pairs.
@@ -118,9 +100,9 @@ extension NSAttributedString {
118
100
- options: The options used by the enumeration. The values can be combined using C-bitwise OR. The values are described in `NSAttributedString.EnumerationOptions`.
119
101
- returns: An array of attribute-range tuples. Each tuples contains a range and the array of attributes that exist in that range.
120
102
*/
121
- public func attributes ( in range: Range < Int > , options: NSAttributedString . EnumerationOptions = [ ] ) -> [ ( [ Attribute ] , Range < Int > ) ] {
103
+ public func swiftyAttributes ( in range: Range < Int > , options: NSAttributedString . EnumerationOptions = [ ] ) -> [ ( [ Attribute ] , Range < Int > ) ] {
122
104
var attributeRanges = [ ( [ Attribute ] , Range < Int > ) ] ( )
123
- enumerateAttributes ( in: range, options: options) { attributes, range, _ in
105
+ enumerateSwiftyAttributes ( in: range, options: options) { attributes, range, _ in
124
106
attributeRanges. append ( ( attributes, range) )
125
107
}
126
108
return attributeRanges
@@ -140,7 +122,7 @@ extension NSAttributedString {
140
122
+ stop: A reference to a Boolean value. The block can set the value to `true` to stop further processing of the set.
141
123
The stop argument is an out-only argument. You should only ever set this Boolean to `true` within the block.
142
124
*/
143
- public func enumerateAttributes ( in enumerationRange: Range < Int > , options: NSAttributedString . EnumerationOptions = [ ] , using block: ( _ attrs: [ Attribute ] , _ range: Range < Int > , _ stop: UnsafeMutablePointer < ObjCBool > ) -> Void ) {
125
+ public func enumerateSwiftyAttributes ( in enumerationRange: Range < Int > , options: NSAttributedString . EnumerationOptions = [ ] , using block: ( _ attrs: [ Attribute ] , _ range: Range < Int > , _ stop: UnsafeMutablePointer < ObjCBool > ) -> Void ) {
144
126
enumerateAttributes ( in: NSRange ( enumerationRange) , options: options) { attributes, range, ptr in
145
127
block ( attributes. swiftyAttributes, range. location ..< ( range. location + range. length) , ptr)
146
128
}
@@ -161,7 +143,7 @@ extension NSAttributedString {
161
143
+ stop: A reference to a Boolean value. The block can set the value to `true` to stop further processing of the set.
162
144
The stop argument is an out-only argument. You should only ever set this Boolean to `true` within the block.
163
145
*/
164
- public func enumerateAttribute ( _ attrName: AttributeName , in enumerationRange: Range < Int > , options: NSAttributedString . EnumerationOptions = [ ] , using block: ( _ value: Any ? , _ range: Range < Int > , _ stop: UnsafeMutablePointer < ObjCBool > ) -> Void ) {
146
+ public func enumerateSwiftyAttribute ( _ attrName: AttributeName , in enumerationRange: Range < Int > , options: NSAttributedString . EnumerationOptions = [ ] , using block: ( _ value: Any ? , _ range: Range < Int > , _ stop: UnsafeMutablePointer < ObjCBool > ) -> Void ) {
165
147
#if swift(>=4.0)
166
148
enumerateAttribute ( attrName, in: NSRange ( enumerationRange) , options: options) { value, range, ptr in
167
149
block ( value, range. location ..< ( range. location + range. length) , ptr)
0 commit comments