I asked the same question on twitter, and it resulted in some interesting finds: https://twitter.com/bitCycle/status/778697998893142016
On Thu, Sep 22, 2016 at 12:41 AM, Zhao Xin <owe...@gmail.com> wrote: > I suggest you defining the variables before using them like Marco does. > Although from the global variable point of view, both way should be fine. > But the glitch does exist, especially in playground. > > Zhaoxin > > On Thu, Sep 22, 2016 at 5:59 AM, Marco S Hyman via swift-users < > swift-users@swift.org> wrote: > >> >> > On Sep 21, 2016, at 2:22 PM, Jens Persson via swift-users < >> swift-users@swift.org> wrote: >> > >> > // This little Swift program compiles (and runs) fine: >> > >> > func foo() -> Int { return a } >> > let a = 1 >> > let b = 2 >> > print(foo()) >> > >> > But if `foo()` returns `b` instead of `a`, I get this compile time >> error: >> > "Use of unresolved identifier `b`” >> >> Interesting. Seems to have something to do with ordering as if you code >> it this way: >> >> let a = 1 >> let b = 2 >> func foo() -> Int { return b } >> print(foo()) >> >> it works fine (Xcode 8 playground). >> _______________________________________________ >> swift-users mailing list >> swift-users@swift.org >> https://lists.swift.org/mailman/listinfo/swift-users >> > >
_______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users