@@ -12,7 +12,7 @@ import CoreFoundation
12
12
open class NSArray : NSObject , NSCopying , NSMutableCopying , NSSecureCoding , NSCoding {
13
13
private let _cfinfo = _CFInfo ( typeID: CFArrayGetTypeID ( ) )
14
14
internal var _storage = [ AnyObject] ( )
15
-
15
+
16
16
open var count : Int {
17
17
guard type ( of: self ) === NSArray . self || type ( of: self ) === NSMutableArray . self else {
18
18
NSRequiresConcreteImplementation ( )
@@ -74,7 +74,38 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
74
74
self . init ( array: objects)
75
75
}
76
76
}
77
-
77
+
78
+ public convenience init ( object anObject: Any ) {
79
+ self . init ( array: [ anObject] )
80
+ }
81
+
82
+ public convenience init ( array: [ Any ] ) {
83
+ self . init ( array: array, copyItems: false )
84
+ }
85
+
86
+ public convenience init ( array: NSArray ) {
87
+ self . init ( array: array as [ AnyObject ] , copyItems: true )
88
+ }
89
+
90
+ public convenience init ( array: [ Any ] , copyItems: Bool ) {
91
+
92
+ let optionalArray : [ AnyObject ] =
93
+ copyItems ?
94
+ array. map { return __SwiftValue. store ( $0) . copy ( ) as! NSObject } :
95
+ array. map { return __SwiftValue. store ( $0) }
96
+
97
+ // This would have been nice, but "initializer delegation cannot be nested in another expression"
98
+ // optionalArray.withUnsafeBufferPointer { ptr in
99
+ // self.init(objects: ptr.baseAddress, count: array.count)
100
+ // }
101
+ let cnt = array. count
102
+ let buffer = UnsafeMutablePointer< AnyObject> . allocate( capacity: cnt)
103
+ buffer. initialize ( from: optionalArray, count: cnt)
104
+ self . init ( objects: buffer, count: cnt)
105
+ buffer. deinitialize ( count: cnt)
106
+ buffer. deallocate ( )
107
+ }
108
+
78
109
open func encode( with aCoder: NSCoder ) {
79
110
guard aCoder. allowsKeyedCoding else {
80
111
preconditionFailure ( " Unkeyed coding is unsupported. " )
@@ -124,33 +155,6 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
124
155
return NSMutableArray ( array: self . allObjects)
125
156
}
126
157
127
- public convenience init ( object anObject: Any ) {
128
- self . init ( array: [ anObject] )
129
- }
130
-
131
- public convenience init ( array: [ Any ] ) {
132
- self . init ( array: array, copyItems: false )
133
- }
134
-
135
- public convenience init ( array: [ Any ] , copyItems: Bool ) {
136
-
137
- let optionalArray : [ AnyObject ] =
138
- copyItems ?
139
- array. map { return __SwiftValue. store ( $0) . copy ( ) as! NSObject } :
140
- array. map { return __SwiftValue. store ( $0) }
141
-
142
- // This would have been nice, but "initializer delegation cannot be nested in another expression"
143
- // optionalArray.withUnsafeBufferPointer { ptr in
144
- // self.init(objects: ptr.baseAddress, count: array.count)
145
- // }
146
- let cnt = array. count
147
- let buffer = UnsafeMutablePointer< AnyObject> . allocate( capacity: cnt)
148
- buffer. initialize ( from: optionalArray, count: cnt)
149
- self . init ( objects: buffer, count: cnt)
150
- buffer. deinitialize ( count: cnt)
151
- buffer. deallocate ( )
152
- }
153
-
154
158
open override func isEqual( _ value: Any ? ) -> Bool {
155
159
switch value {
156
160
case let other as [ Any ] :
0 commit comments