Swift: what's the difference between Array() and [OtherModule.MyType]() -



Swift: what's the difference between Array<OtherModule.MyType>() and [OtherModule.MyType]() -

i'm using type different module, let's phone call othermodule.mytype,

this code:

var = [othermodule.mytype]()

will produce error invalid utilize of '()' phone call value of non-function type '[mytype.type]'

this code won't:

var ax = [othermodule.mytype]

but believe ax not array more, since code

ax.append(othermodule.mytype())

will cause error cannot invoke 'append' argument list of '(mytype)'

so wonder ax is?

besides, code works fine:

var ay = array<othermodule.mytype>() ay.append(othermodule.mytype())

update: i'm using swift 1.2 xcode 6.3

for reason best known swift team (modules scantly documented), module.thing behaves differently thing.

while int type name:

let i: int = 1 // fine // not fine, "expected fellow member name or constructor phone call after type name" allow j = int

swift.int can both:

// used type name allow k: swift.int = 1 allow t = swift.int.self // used value allow x = swift.int // equivalent allow y = int.self tostring(x) == tostring(y) // true

under uses wants value, not type name though. hence works:

// of type [int.type], initialized array // literal of 1 element, int metatype allow = [swift.int]

but trying utilize type name in context fails: [swift.int]() no more valid writing [1]() or let strs = ["fred"]; strs().

this behaviour seems little arbitrary, , may bug/unintentional.

since only way in swift.int can used in context:

array<swift.int>()

is type not value (since types can go between angle brackets), kind of makes sense works while more ambiguous array literal syntax behaves differently.

swift

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -