Files
swift-mirror/test/Interpreter/SDK/Foundation_NSString.swift
Joe Groff 7406986487 SILGen: Class constructors need to return modified self.
-[NSMutableArray init] modifies self, causing NSStringDemo to fail when sil-irgenned because SILGen didn't handle constructors changing 'this' correctly.

Swift SVN r4728
2013-04-13 19:21:10 +00:00

42 lines
1.2 KiB
Swift

// RUN: rm -rf %t/clang-module-cache
// RUN: %swift -module-cache-path=%t/clang-module-cache -sdk=%sdk -i %s | FileCheck %s
// REQUIRES: sdk
import Foundation
var hello : NSString = "Hello, world!"
// CHECK: Hello, world!
println(hello)
var upperHello = hello.uppercaseString()
// CHECK: HELLO, WORLD!
println(upperHello)
// Note: easy way to create an NSDictionary
var strings : NSString = "\"A\" = \"Foo\";\n\"B\" = \"Bar\";\n"
var dict = strings.propertyListFromStringsFileFormat()
// Subscripting an NSDictionary. FIXME: The inner NSString casts are annoying.
// CHECK: A -> Foo
println("A -> " + (dict[NSString("A")] as! NSString))
// CHECK: B -> Bar
println("B -> " + (dict[NSString("B")] as! NSString))
// Creating and subscripting an NSMutableArray
var array = new NSMutableArray(2)
hello = "Hello"
array[0] = hello
array[1] = NSString("world")
// FIXME: NSString string interpolation doesn't work due to lack of
// overload resolution.
// CHECK: Hello, world!
print(array[0] as! NSString)
print(", ");
print(array[1] as! NSString)
println("!")
// Selectors
assert(NSString.instancesRespondToSelector("init"))
assert(!NSString.instancesRespondToSelector("wobble"))