Files
swift-mirror/test/Interpreter/SDK/objc_dynamic_lookup.swift
Dmitri Hrybenko 2cc8fe40d4 stdlib/printing: replace four printing systems with one new one
The old ones were:

- print/println
- printAny
- printf
- Console

The new printing story is just print/println.  Every object can be printed.
You can customize the way it is printed by adopting Printable protocol.  Full
details in comments inside stdlib/core/OutputStream.swift.

Printing is not completely finished yet.  We still have ReplPrintable, which
should be removed, string interpolation still uses String constructors, and
printing objects that don't conform to Printable will result in printing
mangled names.


Swift SVN r18001
2014-05-13 13:07:59 +00:00

49 lines
1.1 KiB
Swift

// RUN: %target-run-simple-swift | FileCheck %s
import Foundation
// Dynamic subscripting of NSArray, dynamic method dispatch
// CHECK: 3
var array : AnyObject = [1, 2, 3, 4, 5]
#if os(OSX)
println(array[2].description)
#else
println(array[2]!.description!())
#endif
// Dynamic subscripting on an array using an object (fails)
// CHECK: NSArray subscript with an object fails
var optVal1 = array["Hello"]
if optVal1 {
#if os(OSX)
println(optVal1.description)
#else
println(optVal1!.description!())
#endif
} else {
println("NSArray subscript with an object fails")
}
// Dynamic subscripting of NSDictionary, dynamic method dispatch
// CHECK: 2
var nsdict : NSDictionary = ["Hello" : 1, "World" : 2]
var dict : AnyObject = nsdict
#if os(OSX)
println(dict["World"].description)
#else
println(dict["World"]!.description!())
#endif
// Dynamic subscripting on an array using an object (fails)
// CHECK: NSDictionary subscript with an object fails
var optVal2 = dict[1]
if optVal2 {
#if os(OSX)
println(optVal2.description)
#else
println(optVal2!.description!())
#endif
} else {
println("NSDictionary subscript with an object fails")
}