@@ -231,8 +231,55 @@ open class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCoding,
231
231
open override var description : String {
232
232
return description ( withLocale: nil )
233
233
}
234
+
235
+ private func getDescription( of object: Any ) -> String ? {
236
+ switch object {
237
+ case is NSArray . Type :
238
+ return ( object as! NSArray ) . description ( withLocale: nil , indent: 1 )
239
+ case is NSDecimalNumber . Type :
240
+ return ( object as! NSDecimalNumber ) . description ( withLocale: nil )
241
+ case is NSDate . Type :
242
+ return ( object as! NSDate ) . description ( with: nil )
243
+ case is NSOrderedSet . Type :
244
+ return ( object as! NSOrderedSet ) . description ( withLocale: nil )
245
+ case is NSSet . Type :
246
+ return ( object as! NSSet ) . description ( withLocale: nil )
247
+ case is NSDictionary . Type :
248
+ return ( object as! NSDictionary ) . description ( withLocale: nil )
249
+ default :
250
+ if let hashableObject = object as? Dictionary < AnyHashable , Any > {
251
+ return hashableObject. _nsObject. description ( withLocale: nil , indent: 1 )
252
+ } else {
253
+ return nil
254
+ }
255
+ }
256
+ }
234
257
235
- open var descriptionInStringsFileFormat : String { NSUnimplemented ( ) }
258
+ open var descriptionInStringsFileFormat : String {
259
+ var lines = [ String] ( )
260
+ for key in self . allKeys {
261
+ let line = NSMutableString ( capacity: 0 )
262
+ line. append ( " \" " )
263
+ if let descriptionByType = getDescription ( of: key) {
264
+ line. append ( descriptionByType)
265
+ } else {
266
+ line. append ( " \( key) " )
267
+ }
268
+ line. append ( " \" " )
269
+ line. append ( " = " )
270
+ line. append ( " \" " )
271
+ let value = self . object ( forKey: key) !
272
+ if let descriptionByTypeValue = getDescription ( of: value) {
273
+ line. append ( descriptionByTypeValue)
274
+ } else {
275
+ line. append ( " \( value) " )
276
+ }
277
+ line. append ( " \" " )
278
+ line. append ( " ; " )
279
+ lines. append ( line. _bridgeToSwift ( ) )
280
+ }
281
+ return lines. joined ( separator: " \n " )
282
+ }
236
283
237
284
/// Returns a string object that represents the contents of the dictionary,
238
285
/// formatted as a property list.
@@ -298,11 +345,14 @@ open class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCoding,
298
345
} else if object is NSSet {
299
346
line += ( object as! NSSet ) . description ( withLocale: locale)
300
347
} else {
301
- line += " \( object) "
348
+ if let hashableObject = object as? Dictionary < AnyHashable , Any > {
349
+ line += hashableObject. _nsObject. description ( withLocale: nil , indent: level+ 1 )
350
+ } else {
351
+ line += " \( object) "
352
+ }
302
353
}
303
354
304
355
line += " ; "
305
-
306
356
lines. append ( line)
307
357
}
308
358
0 commit comments