Saturday, 15 January 2011

ios - Appending to an Int to a collection of type [Int] gives 'not identical' error -



ios - Appending to an Int to a collection of type [Int] gives 'not identical' error -

here's code.

class stack { var size: int = 0 var items: [int] = [] func push(element: int) { items += element // error - '[int]' not identical 'uint8' } func pop() -> int { homecoming items.removelast() } }

everything explicitly typed. how interpreter decide element of uint8 type?

the meaning of + has changed. can utilize 2 arrays. can say:

items += [element]

however, recommend using append instead.

ios swift

No comments:

Post a Comment