Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

The only work around for this that I've come up with thus far is something that looks like this something that looks like this:

func foo() -> Int {
 struct Holder {
 static var timesCalled = 0
 }
 return ++Holder.timesCalled;
}

It's pretty clunky in my opinion, and I'm not sure why Apple doesn't just allow straight static function variables, but this seems quite a bit cleaner than your approach.

The only work around for this that I've come up with thus far is something that looks like this:

func foo() -> Int {
 struct Holder {
 static var timesCalled = 0
 }
 return ++Holder.timesCalled;
}

It's pretty clunky in my opinion, and I'm not sure why Apple doesn't just allow straight static function variables, but this seems quite a bit cleaner than your approach.

The only work around for this that I've come up with thus far is something that looks like this:

func foo() -> Int {
 struct Holder {
 static var timesCalled = 0
 }
 return ++Holder.timesCalled;
}

It's pretty clunky in my opinion, and I'm not sure why Apple doesn't just allow straight static function variables, but this seems quite a bit cleaner than your approach.

Source Link
nhgrif
  • 25.4k
  • 3
  • 64
  • 129

The only work around for this that I've come up with thus far is something that looks like this:

func foo() -> Int {
 struct Holder {
 static var timesCalled = 0
 }
 return ++Holder.timesCalled;
}

It's pretty clunky in my opinion, and I'm not sure why Apple doesn't just allow straight static function variables, but this seems quite a bit cleaner than your approach.

default

AltStyle によって変換されたページ (->オリジナル) /