2

With Xcode 6.1.1, run xcrun swift, and then:

1> let a: [String] = []
a: [String] = 0 values

2> let b = Array<String>()
b: [String] = 0 values

3> let c = [String]()
c: [(String)] = 0 values

Why was c initialised to an array of 1-tuples?

1
  • It's just a notation. You're looking into the sausage factory so you see the sausage. Commented Feb 2, 2015 at 16:27

1 Answer 1

2

It's just a notation. You're looking into the sausage factory so you see the bits of sausage; that's the price of using the REPL. Ask yourself in what way a 1-tuple differs from its contents... It doesn't. It's still just an array of string:

  1> var c = [String]()
c: [(String)] = 0 values
  2> c.append("hello")
  3> c
$R0: [(String)] = 1 value {
  [0] = "hello"
}

So [0] = "hello". No tuples here.

Sign up to request clarification or add additional context in comments.

1 Comment

To further elaborate, as far as the language is concerned, a 1-tuple ((String)) and a single value (String) are indistinguishable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.