Skip to content

Instantly share code, notes, and snippets.

@jandamm
Last active March 10, 2018 17:07
Show Gist options
  • Save jandamm/3421199e0f70d0806cd5a3d02ab6cb6d to your computer and use it in GitHub Desktop.
Save jandamm/3421199e0f70d0806cd5a3d02ab6cb6d to your computer and use it in GitHub Desktop.
import UIKit
func returnsNil() -> UIView? {
weak var view: UIView? = UIView()
return view
}
func returnsView1() -> UIView? {
weak var view: UIView?
view = UIView()
return view
}
func returnsView2() -> UIView? {
weak var view: UIView?
var v: UIView? = UIView()
view = v
v = nil
return view
}
var v1: UIView? = UIView()
func returnsView3() -> UIView? {
weak var view: UIView? = v1
v1 = nil
return view
}
var v2: UIView? = UIView()
func returnsView4() -> UIView? {
weak var view: UIView?
view = v2
v2 = nil
return view
}
returnsNil() // nil
returnsView1() // UIView
returnsView2() // UIView
returnsView3() // UIView
returnsView4() // UIView
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment