Xcode 4:
NSArray *names = [[NSArray alloc] initWithObjects: @“Tom”, @“Dick”, @“Harry”, nil];
Xcode 5:
NSArray *names = @[@“Tom”, @“Dick”, @“Harry”];
Swift:
let names = [“Tom”, “Dick”, “Harry”]
Xojo:
names = (“Tom”, “Dick”, “Harry”)
[ok, cheated a bit, left the dim statement out]
actually, I believe in Swift, you still need the @ signs, so this is what it should be.
let names = [@“Tom”, @"!@#$%", @“Harry”]
In Xojo, you need the Array keyword.
I don’t think you need “@” in Swift. Can anyone confirm one way or the other?
Xojo:
Dim names() As String = Array(“a”, “b”, “c”)
Swift:
var names = [“a”, “b”, “c”]
You most certainly don’t need any @ symbols in Swift. It was a way to separate the Objective-C part of the C code. Swift has no such baggage.
var names = [“a”, “b”, “c”]
is the short way, using type inference, for the explicit:
var names: String[] = [“a”, “b”, “c”]
Objective-C string concatenation:
NSString *myString = @"Stop";
NSString *myString2 = [myString stringByAppendingString:@" all Off-Topic threads"];
Swift string concatenation:
var myString = "Stop"
var myString2 = myString + " all Off-Topic threads"
Simple.
Norman_P
(Norman P)
10
we could certainly rewrite the xojo language and use [] () ; and all those C idioms
BUT it’d be “xojo++” or “xojo swift” or something else
given the language we have and the spec it has today I’d say the chance is close to 0
What is Swift’s equivalent for Variant? Because I’m pretty sure I tried this and it worked:
var n = [1, "2", 3]
[quote=96909:@Kem Tekinay]
var n = [1, "2", 3]
[/quote]
That wouldn’t work, you can’t mix types like that in a Swift array.
You should check out Swift enums though - wow!
If you have an hour, I highly recommend checking out the Introduction to Swift session video. https://developer.apple.com/videos/wwdc/2014/
(I think that should be available if you don’t have a paid-up Developer account, but I’m not sure cos, well, I do)
[quote=96911:@Gavin Smith]That wouldn’t work, you can’t mix types like that in a Swift array.
You should check out Swift enums though - wow![/quote]
I just tried this code and it ran:
var n = ["a", 2, "c" ]
println( n )
So what did I end up with in n?
I think there is a type called “Any”
[quote=96921:@Kem Tekinay]I just tried this code and it ran:
var n = ["a", 2, "c" ]
println( n )
So what did I end up with in n?[/quote]
It ran? It doesn’t run here. What did it print out?
Perhaps it will spit stuff out in a Playground but it’s not a valid array as they require only one type. This is what I see in my Xcode Playground.

var v = Any
v.append(42)
v.append(3.14)
v.append(“hello”)
v.append((3.0, 5.0))
I started a new CLI project to test.