am now getting the following error
Expression resolves to an unused property with the following code
func setlayout(){
//containerStackView.translatesAutoresizingMaskIntoConstraints
containerStackView.topAnchor.constraint(equalTo:view.safeAreaLayoutGuide.topAnchor, constant: 20).isActive
containerStackView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor).isActive
containerStackView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor).isActive
}
On the following code
func setlayout(){
containerStackView.topAnchor.constraint(equalTo: view.topAnchor, constant: 0)
containerStackView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0)
}
However the containerStackView is not showing at all.
My code:
import UIKit
class ViewController: UIViewController {
/* V VIEWS */
let containerStackView = UIStackView()
let verticalStackView = UIStackView()
let verticalViewOne = UIView()
let verticalViewTwo = UIView()
let verticalViewThree = UIView()
override func viewDidLoad() {
super.viewDidLoad()
setupViews()
setupHierachy()
setlayout()
}
func setupViews(){
verticalStackView.axis = .vertical
verticalStackView.translatesAutoresizingMaskIntoConstraints = false
verticalStackView.distribution = .fillEqually
verticalViewOne.backgroundColor = .red
containerStackView.axis = .vertical
containerStackView.spacing = 15
containerStackView.distribution = .fillEqually
}
func setupHierachy(){
view.addSubview(containerStackView)
view.addSubview(verticalStackView)
verticalStackView.addArrangedSubview(verticalViewOne)
containerStackView.addArrangedSubview(verticalStackView)
}
func setlayout(){
//containerStackView.translatesAutoresizingMaskIntoConstraints
containerStackView.topAnchor.constraint(equalTo:view.safeAreaLayoutGuide.topAnchor, constant: 20).isActive
containerStackView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor).isActive
containerStackView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor).isActive
}
}