As soon as you reindent the entire code correctly, your
viewDidLoad() is completely included in the definition of the
Swift allows this nested function definition as a language specification, but the nested function definition inside is not considered an instance method and is only a valid local function within the outer method.
Therefore, it is determined that the original
viewDidLoad() does not exist in your code (as an instance method), and the
viewDidLoad() inside (nested) is also not called.
(It shouldn't be too hard to issue a "some local functions are not in use" warning around here…)
Anyway, as a result, your
myTimer is not configured with a correctly scheduled
Timer and has a
Timer instance (made with an initializer
init() that is not documented how it behaves).Naturally, nothing happens that you try to schedule.
One of the reasons these errors are hard to find is that your property
myTimer declaration is the code for a typical bad practice.
Unless you clearly understand what the
Timer() instance is, you should never such a property declaration.(Unfortunately, such a very bad way of writing often appears at the top of the search results.)
If you declare as shown in , you will quickly notice that the
myTimer that should have been initialized remains
If you rewrite your code, including that, it will look like this
Other things to check, my current recommended writing style, etc. are indicated by comments with
##.Please check the contents before trying.
© 2022 OneMinuteCode. All rights reserved.