Take this code:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var i = 0
//let v1 = UIView(frame:CGRectMake(113, 111, 132, 194))
//v1.backgroundColor = UIColor.redColor()
//self.view.addSubview(v1)
for v in self.view.subviews as! [UIView] {
v.removeFromSuperview()
i++
}
println(i)
}
}
The for loop removes all subviews from the superview. At the end of the loop, i
is 2, meaning there were 2 subviews removed. Since I didn't add any myself, what are these subviews?
There are two hidden layers in default UIViewController. When you print the output of your code you'll find