3

While reading about Big O Notation on a blog, there was a reference to the following line of code:

let numberList : Array<Int> = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 

It catches you off guard because it has the keyword type Int inside of angle brackets which I've considered this is how generics syntax works. So I investigated in a playground if this line of code equates to what I'm used to seeing:

let numberList : Array<Int> = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 
let numberList2 : [Int] = [1,2,3,4,5,6,7,8,9,10]
if numberList == numberList2{
    print("They're the same")
}

Before I move forward, I just want to be sure and ask others if this is definitely the same and it doesn't matter which format you choose.

Also I'm thinking this isn't a duplicate because I've clicked on all the swift array links when posing a question before posting this one.

1 Answer 1

5

Before I move forward, I just want to be sure and ask others if this is definitely the same and it doesn't matter which format you choose.

Yes, they mean the same thing and it doesn't matter which you use. [Int] is pure syntactic sugar for Array<Int>, no more no less.

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

4 Comments

"which I've considered this is how generics syntax works" Very good, absolutely right. Array is a generic struct.
Might want to read my free online book apeth.com/swiftBook/ch04.html#_array
Hey!! @matt I have your book on my nook or google play and it has helped tremendously. Huge huge pleasure to have you answer my question and meet you online.
You didn't actually need me. You did all the detective work yourself!

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.