> > var s: String? = "Foo" > print(s?.characters) > > The result indicates that s?.characters is indeed an Optional instance, > indicating that s?.characters.count should be illegal. > > Why is s?.characters.count a legal expression?
See print(s?.characters.count) — you get the optional despite count not being defined as optional Also, try this: struct Foo { let bar: Int } var foo: Foo? = Foo(bar: 42) print(foo?.bar) Then try this: struct Foo { let bar: Int let baz: Int? } var foo: Foo? = Foo(bar: 42, baz: 69) print(foo?.bar) print(foo?.baz?) This may give you some ideas. Best regards, Rimantas
_______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users