You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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…