@@ -49,7 +49,43 @@ open class NSSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCodi
49
49
_storage. insert ( __SwiftValue. store ( obj) )
50
50
}
51
51
}
52
-
52
+
53
+ public convenience init ( array: [ Any ] ) {
54
+ let buffer = UnsafeMutablePointer< AnyObject> . allocate( capacity: array. count)
55
+ for (idx, element) in array. enumerated ( ) {
56
+ buffer. advanced ( by: idx) . initialize ( to: __SwiftValue. store ( element) )
57
+ }
58
+ self . init ( objects: buffer, count: array. count)
59
+ buffer. deinitialize ( count: array. count)
60
+ buffer. deallocate ( )
61
+ }
62
+
63
+ public convenience init ( set: Set < AnyHashable > ) {
64
+ self . init ( set: set, copyItems: false )
65
+ }
66
+
67
+ public convenience init ( set anSet: NSSet ) {
68
+ self . init ( array: anSet. allObjects)
69
+ }
70
+
71
+ public convenience init ( set: Set < AnyHashable > , copyItems flag: Bool ) {
72
+ if flag {
73
+ self . init ( array: set. map {
74
+ if let item = $0 as? NSObject {
75
+ return item. copy ( )
76
+ } else {
77
+ return $0
78
+ }
79
+ } )
80
+ } else {
81
+ self . init ( array: Array ( set) )
82
+ }
83
+ }
84
+
85
+ public convenience init ( object: Any ) {
86
+ self . init ( array: [ object] )
87
+ }
88
+
53
89
public required convenience init ? ( coder aDecoder: NSCoder ) {
54
90
guard aDecoder. allowsKeyedCoding else {
55
91
preconditionFailure ( " Unkeyed coding is unsupported. " )
@@ -167,44 +203,6 @@ open class NSSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCodi
167
203
return self . count
168
204
}
169
205
170
- public convenience init ( array: [ Any ] ) {
171
- let buffer = UnsafeMutablePointer< AnyObject> . allocate( capacity: array. count)
172
- for (idx, element) in array. enumerated ( ) {
173
- buffer. advanced ( by: idx) . initialize ( to: __SwiftValue. store ( element) )
174
- }
175
- self . init ( objects: buffer, count: array. count)
176
- buffer. deinitialize ( count: array. count)
177
- buffer. deallocate ( )
178
- }
179
-
180
- public convenience init ( set: Set < AnyHashable > ) {
181
- self . init ( set: set, copyItems: false )
182
- }
183
-
184
- public convenience init ( set: Set < AnyHashable > , copyItems flag: Bool ) {
185
- if flag {
186
- self . init ( array: set. map {
187
- if let item = $0 as? NSObject {
188
- return item. copy ( )
189
- } else {
190
- return $0
191
- }
192
- } )
193
- } else {
194
- self . init ( array: Array ( set) )
195
- }
196
- }
197
- }
198
-
199
- extension NSSet {
200
-
201
- public convenience init ( object: Any ) {
202
- self . init ( array: [ object] )
203
- }
204
- }
205
-
206
- extension NSSet {
207
-
208
206
open var allObjects : [ Any ] {
209
207
if type ( of: self ) === NSSet . self || type ( of: self ) === NSMutableSet . self {
210
208
return _storage. map { __SwiftValue. fetch ( nonOptional: $0) }
@@ -346,8 +344,10 @@ extension NSSet : Sequence {
346
344
}
347
345
}
348
346
349
- extension NSSet : CustomReflectable {
350
- public var customMirror : Mirror { NSUnimplemented ( ) }
347
+ extension NSSet : CustomReflectable {
348
+ public var customMirror : Mirror {
349
+ return Mirror ( reflecting: self . _storage)
350
+ }
351
351
}
352
352
353
353
open class NSMutableSet : NSSet {
0 commit comments