Please see the code below:
class myViewMgr {
var myView: UIView?
func create() {
myView = UIView()
myView!.translatesAutoresizingMaskIntoConstraints = false
myView!.backgroundColor = UIColor.blackColor()
myView!...
myView!...
}
}
I have a class and a variable myView
which might be empty. Inside create()
, I create an instance for it and start using it. And I have to force unwrapping myView
in the following code.
I am wondering if I am doing something wrong in some general Swift concept? Any advise to help me and correct me is appreciated.