Skip to content

Commit 976f962

Browse files
committed
Island/Darwin: cast operators for Array too NSArray (even though int uses List<T> under the hood); ToSwiftArray extension for sequences
1 parent 076ad86 commit 976f962

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Source/Array.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,20 @@ public struct Array<T>
191191
return [T](list)
192192
}
193193

194+
#if ISLAND && DARWIN
195+
public static func __implicit(_ array: NSArray<T>) -> [T] {
196+
return List<T>(array)
197+
}
198+
199+
public static func __implicit(_ array: [T]) -> NSArray<T> {
200+
return array.list.ToNSArray()
201+
}
202+
203+
public static func __implicit(_ list: [T]) -> NSMutableArray<T> {
204+
return list.list.ToNSMutableArray()
205+
}
206+
#endif
207+
194208
#if COCOA
195209
public static func __implicit(_ list: PlatformImmutableList<T>) -> [T] {
196210
return [T](list)

Source/Sequence_Extensions.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ public extension ISequence /*: ICustomDebugStringConvertible*/ { // 74092: Silve
2424
return array as! ISequence<T> // 74041: Silver: warning for "as" cast that should be known safe
2525
}
2626

27+
public func ToSwiftArray() -> [T] {
28+
if let array = self as? [T] {
29+
return array.platformList
30+
}
31+
var result = [T]()
32+
for i in self {
33+
result.append(i)
34+
}
35+
return result
36+
}
37+
2738
public var count: Int {
2839
return self.Count()
2940
}

0 commit comments

Comments
 (0)