<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div dir="ltr" class=""><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><div class=""><br class=""></div></div></div></blockquote><div class="">You are right Dan. I did give it a try previously from the REPL. And yes, fails if scripted. </div></div></div></blockquote><div><br class=""></div><div>I think what you're running into here is the different ways the REPL, Playgrounds, and .swift files are initialized (esp. with respect to globals). There's some interesting talk about this on the (original) Swift blog at Apple: <a href="https://developer.apple.com/swift/blog/#article-18" class="">https://developer.apple.com/swift/blog/#article-18</a></div><div><br class=""></div><div>"Most Swift files in your app are order-independent, meaning you can use a type before it is defined, and can even import modules at the bottom of the file (although that is not recommended Swift style.)"</div><div><br class=""></div><div>"Code within a playground file is order-dependent, run in top-down lexical order. For example, you can’t use a type before you define it."</div><div><br class=""></div><div>"The exception is a special file named “main.swift”, which behaves much like a playground file, but is built with your app’s source code. "</div><div><br class=""></div><div>"Given how Swift determines where to start executing an app, how should global variables work? ... In a single-file program, code is executed top-down, similar to the behavior of variables within a function. Pretty simple. The answer for complex apps is less obvious... [Swift] runs the initializer for a global the first time it is referenced, similar to Java ... which is the best of all worlds: it allows custom initializers, startup time in Swift scales cleanly with no global initializers to slow it down, and the order of execution is completely predictable."</div><div><br class=""></div><div>This was from back in beta days, but I'm pretty sure it still applies.</div><div><br class=""></div><div>-- </div><div>Cheers!</div><div>-jemmons</div></div></body></html>