Confused about Swift Array Declarations

First two have the same effect.

  1. declare a variable array1_OfStrings, let it choose the type itself. When it sees [String](), it smartly knows that’s type array of string.

  2. You set the variable array2_OfStrings as type array of string, then you say it’s empty by []

  3. This is different because you just tell you want array3_OfStrings to be type array of string, but not given it an initial value.

I think the first one is recommended as The Swift Programming Language uses it more often.

Leave a Comment