@@ -264,11 +264,101 @@ public class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCodin
264
264
return matching
265
265
}
266
266
267
- public override var description : String { NSUnimplemented ( ) }
267
+ /// A string that represents the contents of the dictionary, formatted as
268
+ /// a property list (read-only)
269
+ ///
270
+ /// If each key in the dictionary is an NSString object, the entries are
271
+ /// listed in ascending order by key, otherwise the order in which the entries
272
+ /// are listed is undefined. This property is intended to produce readable
273
+ /// output for debugging purposes, not for serializing data. If you want to
274
+ /// store dictionary data for later retrieval, see
275
+ /// [Property List Programming Guide](https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/PropertyLists/Introduction/Introduction.html#//apple_ref/doc/uid/10000048i)
276
+ /// and [Archives and Serializations Programming Guide](https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Archiving/Archiving.html#//apple_ref/doc/uid/10000047i).
277
+ public override var description : String {
278
+ get {
279
+ return descriptionWithLocale ( nil )
280
+ }
281
+ }
282
+
268
283
public var descriptionInStringsFileFormat : String { NSUnimplemented ( ) }
269
- public func descriptionWithLocale( locale: AnyObject ? ) -> String { NSUnimplemented ( ) }
270
- public func descriptionWithLocale( locale: AnyObject ? , indent level: Int ) -> String { NSUnimplemented ( ) }
271
-
284
+
285
+ /// Returns a string object that represents the contents of the dictionary,
286
+ /// formatted as a property list.
287
+ ///
288
+ /// - parameter locale: An object that specifies options used for formatting
289
+ /// each of the dictionary’s keys and values; pass `nil` if you don’t
290
+ /// want them formatted.
291
+ public func descriptionWithLocale( locale: AnyObject ? ) -> String {
292
+ return descriptionWithLocale ( locale, indent: 0 )
293
+ }
294
+
295
+ /// Returns a string object that represents the contents of the dictionary,
296
+ /// formatted as a property list.
297
+ ///
298
+ /// - parameter locale: An object that specifies options used for formatting
299
+ /// each of the dictionary’s keys and values; pass `nil` if you don’t
300
+ /// want them formatted.
301
+ ///
302
+ /// - parameter level: Specifies a level of indentation, to make the output
303
+ /// more readable: the indentation is (4 spaces) * level.
304
+ ///
305
+ /// - returns: A string object that represents the contents of the dictionary,
306
+ /// formatted as a property list.
307
+ public func descriptionWithLocale( locale: AnyObject ? , indent level: Int ) -> String {
308
+ if level > 100 { return " ... " }
309
+
310
+ var lines = [ String] ( )
311
+ let indentation = String ( count: level * 4 , repeatedValue: Character ( " " ) )
312
+ lines. append ( indentation + " { " )
313
+
314
+ for key in self . allKeys {
315
+ var line = String ( count: ( level + 1 ) * 4 , repeatedValue: Character ( " " ) )
316
+
317
+ if key is NSArray {
318
+ line += ( key as! NSArray ) . descriptionWithLocale ( locale, indent: level + 1 )
319
+ } else if key is NSDate {
320
+ line += ( key as! NSDate ) . descriptionWithLocale ( locale)
321
+ } else if key is NSDecimalNumber {
322
+ line += ( key as! NSDecimalNumber ) . descriptionWithLocale ( locale)
323
+ } else if key is NSDictionary {
324
+ line += ( key as! NSDictionary ) . descriptionWithLocale ( locale, indent: level + 1 )
325
+ } else if key is NSOrderedSet {
326
+ line += ( key as! NSOrderedSet ) . descriptionWithLocale ( locale, indent: level + 1 )
327
+ } else if key is NSSet {
328
+ line += ( key as! NSSet ) . descriptionWithLocale ( locale)
329
+ } else {
330
+ line += " \( key) "
331
+ }
332
+
333
+ line += " = "
334
+
335
+ let object = objectForKey ( key) !
336
+ if object is NSArray {
337
+ line += ( object as! NSArray ) . descriptionWithLocale ( locale, indent: level + 1 )
338
+ } else if object is NSDate {
339
+ line += ( object as! NSDate ) . descriptionWithLocale ( locale)
340
+ } else if object is NSDecimalNumber {
341
+ line += ( object as! NSDecimalNumber ) . descriptionWithLocale ( locale)
342
+ } else if object is NSDictionary {
343
+ line += ( object as! NSDictionary ) . descriptionWithLocale ( locale, indent: level + 1 )
344
+ } else if object is NSOrderedSet {
345
+ line += ( object as! NSOrderedSet ) . descriptionWithLocale ( locale, indent: level + 1 )
346
+ } else if object is NSSet {
347
+ line += ( object as! NSSet ) . descriptionWithLocale ( locale)
348
+ } else {
349
+ line += " \( object) "
350
+ }
351
+
352
+ line += " ; "
353
+
354
+ lines. append ( line)
355
+ }
356
+
357
+ lines. append ( indentation + " } " )
358
+
359
+ return lines. joinWithSeparator ( " \n " )
360
+ }
361
+
272
362
public func isEqualToDictionary( otherDictionary: [ NSObject : AnyObject ] ) -> Bool {
273
363
if count != otherDictionary. count {
274
364
return false
0 commit comments