0

How can I have a static variable within a function as shown below?

func addItem(petItem:Item) -> Bool {
    var static count = 0  //... pseudo code
...

...Or must I have all static codes at the top of the file (global area)?

Frederick C. Lee
  • 9,019
  • 17
  • 64
  • 105

1 Answers1

0

Or must I have all static codes at the top of the file (global area)?

Yep, that. You need to declare your variable in the scope where it will persist. Exactly where that should be depends on what you are trying to achieve.

Alex Wayne
  • 178,991
  • 47
  • 309
  • 337