@@ -99,25 +99,61 @@ public struct Dictionary<Key, Value> /*: INSFastEnumeration<T>*/
9999 }
100100
101101 //
102- // Operators
102+ // Casts
103103 //
104104
105- public static func __implicit( _ dictionary: PlatformDictionary < Key , Value > ) -> [ Key : Value ] {
106- return [ Key: Value] ( dictionary)
107- }
105+ // Cast from/to platform type
108106
109- public static func __explicit ( _ dictionary: PlatformDictionary < Key , Value > ) -> [ Key : Value ] {
107+ public static func __implicit ( _ dictionary: PlatformDictionary < Key , Value > ) -> [ Key : Value ] {
110108 return [ Key: Value] ( dictionary)
111109 }
112110
113111 public static func __implicit( _ dictionary: [ Key : Value ] ) -> PlatformDictionary < Key , Value > {
114112 return dictionary. platformDictionary
115113 }
116114
117- public static func __explicit( _ dictionary: [ Key : Value ] ) -> PlatformDictionary < Key , Value > {
118- return dictionary. platformDictionary
115+ // Darwin only: cast from/to Cocoa type
116+
117+ #if DARWIN
118+ #if ISLAND
119+ public static func __implicit( _ dictionary: NSDictionary < Key , Value > ) -> [ Key : Value ] {
120+ return Dictionary < Key , Value > ( dictionary)
121+ }
122+
123+ public static func __implicit( _ dictionary: [ Key : Value ] ) -> NSDictionary < Key , Value > {
124+ return dictionary. dictionary. ToNSDictionary ( )
119125 }
120126
127+ public static func __implicit( _ list: [ Key : Value ] ) -> NSMutableDictionary < Key , Value > {
128+ return Dictionary . dictionary. ToNSDictionary ( )
129+ }
130+ #else
131+ public static func __implicit( _ list: [ Key : Value ] ) -> PlatformImmutableDictionary < Key , Value > {
132+ return Dictionary . platformFictionary
133+ }
134+ #endif
135+ #endif
136+
137+ // Cocoa only: cast from/to different generic Cocoa type
138+
139+ #if TOFFEE || DARWIN
140+ public static func __explicit< Key2, Value2> ( _ dictionary: NSDictionary < Key2 , Value2 > ) -> [ Key : Value ] {
141+ return ( dictionary as! NSDictionary < Key , Value > ) as! [ Key : Value ]
142+ }
143+
144+ public static func __explicit< Key2, Value2> ( _ dictionary: [ Key : Value ] ) -> NSDictionary < Key2 , Value2 > {
145+ return ( dictionary as! NSDictionary < Key , Value > ) as! NSDictionary < Key2 , Value2 >
146+ }
147+
148+ public static func __explicit< Key2, Value2> ( _ dictionary: [ Key : Value ] ) -> NSMutableDictionary < Key2 , Value2 > {
149+ return ( dictionary as! NSMutableDictionary < Key , Value > ) as! NSMutableDictionary < Key2 , Value2 >
150+ }
151+ #endif
152+
153+ //
154+ // Operators
155+ //
156+
121157 public static func + < T> ( lhs: [ Key : Value ] , rhs: [ Key : Value ] ) -> [ Key : Value ] {
122158 var result = lhs
123159 for k in rhs. keys {
@@ -324,7 +360,7 @@ public struct Dictionary<Key, Value> /*: INSFastEnumeration<T>*/
324360 #endif
325361 }
326362
327- public var keys : ISequence < Key > { // we deliberatey return a sequence, not an array , for efficiency and flexibility.
363+ public var keys : ISequence < Key > { // we deliberatey return a sequence, not an dictionary , for efficiency and flexibility.
328364 #if JAVA
329365 return dictionary. keySet ( )
330366 #elseif CLR || ISLAND
@@ -334,7 +370,7 @@ public struct Dictionary<Key, Value> /*: INSFastEnumeration<T>*/
334370 #endif
335371 }
336372
337- public var values : ISequence < Value > { // we deliberatey return a sequence, not an array , for efficiency and flexibility.
373+ public var values : ISequence < Value > { // we deliberatey return a sequence, not an dictionary , for efficiency and flexibility.
338374 #if JAVA
339375 return dictionary. values ( )
340376 #elseif CLR || ISLAND
0 commit comments