user266003
user266003

Reputation:

Declaring an array in Swift

What's the difference between these 3:

struct A {
  let myVal: Array<Char>
  let myVal2: [char]
  let myVal3: Array<CChar>
}

Which one is more common or recommended to be used?

Upvotes: 0

Views: 86

Answers (2)

matt
matt

Reputation: 535944

There is no difference between Array<Thing> and [Thing]; the latter is syntactic sugar for the former.

Hence the only difference between your three declarations is the difference between the three element types: Char (whatever that is), char (whatever that is - a type name starting with a small letter is really bad practice in Swift, though), and CChar (that's the only one I've ever heard of). The recommended one of those three is: whatever it is you want an array of.

Upvotes: 3

rshankar
rshankar

Reputation: 3085

CChar is Swift equivalent of C Primitive type - It is recommended to use Swift data type where it is possibl.- Apple Documentation

The recommended usage as per this style guide is the shortcut version

myValue: [CChar]

Hope this helps

Upvotes: 0

Related Questions