Skip to content

Instantly share code, notes, and snippets.

@sketchytech
Created September 12, 2014 19:07
Show Gist options
  • Save sketchytech/673219e0ff2d88ebec86 to your computer and use it in GitHub Desktop.
Save sketchytech/673219e0ff2d88ebec86 to your computer and use it in GitHub Desktop.
#Swiftlang pub quiz: identify the file that will crash; bonus points if you can identify the most memory-friendly file.
import UIKit
class ViewController: UIViewController {
var a:Foo? = Foo()
override func viewDidLoad() {
super.viewDidLoad()
var b = a!.myFunc
a = nil
println(b())
}
}
class Foo {
var bzz = "bzz"
lazy var myFunc:()->() = {print(self.bzz)}
var szz:String? {
return self.bzz
}
deinit {
println("deinit \(bzz)")
}
}
import UIKit
class ViewController: UIViewController {
var a:Foo? = Foo()
override func viewDidLoad() {
super.viewDidLoad()
var b = a!.myFunc
a = nil
println(b())
}
}
class Foo {
var bzz = "bzz"
lazy var myFunc:()->() = {[unowned self] in print(self.bzz)}
var szz:String? {
return self.bzz
}
deinit {
println("deinit \(bzz)")
}
}
import UIKit
class ViewController: UIViewController {
var a:Foo? = Foo()
override func viewDidLoad() {
super.viewDidLoad()
var b = a!.myFunc
println(b())
a = nil
}
}
class Foo {
var bzz = "bzz"
lazy var myFunc:()->() = {[unowned self] in print(self.bzz)}
var szz:String? {
return self.bzz
}
deinit {
println("deinit \(bzz)")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment