Error message

16 views
Skip to first unread message

Marco S Hyman

unread,
Feb 9, 2015, 10:31:55 PM2/9/15
to swift-l...@googlegroups.com
Am I the only one who finds this error message odd?

'Foo?' does not have a member named 'variable'.

in this code:

class Foo {
var variable: Int = 42
}

var foo: Foo? = Foo()

if let bar = foo.variable { // error here -- forgot the ? after foo.
println("foo.variable is \(bar)")
}

foo? does have a valid member named variable if it is not nil
foo.variable is bogus since foo is an optional.

Marc

Jens Alfke

unread,
Feb 10, 2015, 2:42:17 AM2/10/15
to Marco S Hyman, swift-l...@googlegroups.com

On Feb 9, 2015, at 7:31 PM, Marco S Hyman <ma...@snafu.org> wrote:

Am I the only one who finds this error message odd?

'Foo?' does not have a member named 'variable'.

It makes sense to me. “Foo?” is not the same as Foo; it’s shorthand for something like Optional<Foo>, which does not have a member named ‘variable’.

I guess the message would be clearer if it said something like “You forgot to unwrap ‘foo’”. I suppose that kind of polish will get added to the compiler over time; right now they still have bigger issues to work on…

—Jens
Reply all
Reply to author
Forward
0 new messages