October 2019
Intermediate to advanced
434 pages
11h 54m
English
You can also define mutable top-level properties if you need to track some type of global state. The following snippet shows an example of such a property:
var screenCount = 0
We've defined an integer variable that can be accessed and modified from anywhere in the defined scope:
screenCount++
In this case, it's public, so it can be accessed from anywhere within the code base. In the next section, we'll look at using companion objects as a means of scoping this kind of top-level property.
Read now
Unlock full access