New in Swift Beta 3

7 thoughts
last posted July 12, 2014, 4:05 p.m.

6 earlier thoughts

0

This fails in Beta 3:

``` struct Foo {}

struct Bar { var data: [Foo] init() { data = Foo } func test() { data[2] = Foo() } } ```

with

error: '@lvalue $T7' is not identical to 'Foo' at the data[2] = Foo() line.

Just to be clear, the following works in the initial release:

struct Foo {} struct Bar { var data: Foo[] init() { data = Foo[](count: 5, repeatedValue: Foo()) } func test() { data[2] = Foo() } }

UPDATE: The failure is not because Foo is empty. The following fails:

struct Foo { let i: Int } struct Bar { var data: [Foo] init() { data = [Foo](count: 5, repeatedValue: Foo(i:2)) } func test() { data[2] = Foo(i:2) } }

with error: '@lvalue $T8' is not identical to 'Foo'

UPDATE 2: changing Bar to a class fixes the issue. Hat tip to Andy Dirnberger for the suggestion.