“Use of unresolved identifier” with Swift

后端 未结 1 431
臣服心动
臣服心动 2021-01-05 10:32

I am rewriting one of my apps in Swift, that displays live weather data for South Kohala. Love Swift so far!

I\'m having one small problem that is holding things up

相关标签:
1条回答
  • 2021-01-05 11:09

    It is because List is purely local to the inside of viewDidLoad; where you've declared it, other methods cannot see it.

    Contrast, for example, forecastsTable, which is declared outside any method, which means that any method can see it.

    This behavior is called "scope" and is crucial to any programming language. Variables declared inside a method are neither visible outside it nor do they persist when that method has finished running. Thus, in your example, not only is List not visible when cellForRowAtIndex runs, it doesn't even exist when cellForRowAtIndex runs - it has been destroyed long before.

    0 讨论(0)
提交回复
热议问题