I'm currently stuck to understand which variables are considered to be local, and which are global.
In docs we can read that:
Global variables are variables that are defined outside of any function, method, closure, or type context.
I'm guessing that: variables defined in type context ==
type/instance variables defined inside class/struct?
For example:
var foo = "foo" // global variable
class Foobar {
static var foo = "foo" // local variable -> declared inside Foobar type context
var bar = "bar" // local variable -> declared inside Foobar type context
func foobar() {
var foo = "" // local variable -> declared inside method
}
}
You are absolutely correct, variables defined inside class context become either instance variables or type variables.cVariables defined inside the context of a function, method, or a closure become local variables.
A declaration of a global variable must be at the top level, outside of classes, functions, and so on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With