I’m attempting to construct and it gained’t let me, I’ve adopted different recommendation on stack overflow to initialize my variables however nonetheless getting this error. I’m attempting to construct a view programmatically.
class PropertyViewController: UIViewController {
personal var valueLabel = UILabel()
personal (set) var home: Home
init(
valueLabel: UILabel,
home: Home
) {
self.valueLabel = valueLabel
self.home = home
tremendous.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been applied")
}
override func viewDidLoad() {
tremendous.viewDidLoad()
// Do any further setup after loading the view.
self.view.backgroundColor = .purple
valueLabel.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(valueLabel)
setUpLabel()
setUpConstraints()
}
func setUpLabel() {
valueLabel.textual content = "homes.postcode"
valueLabel.textColor = .black
}
func setUpConstraints() {
valueLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
valueLabel.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
}
}
Scene delegate
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, choices connectionOptions: UIScene.ConnectionOptions) {
// Use this methodology to optionally configure and fasten the UIWindow window
to the offered UIWindowScene scene
.
// If utilizing a storyboard, the window
property will robotically be initialized and connected to the scene.
// This delegate doesn’t suggest the connecting scene or session are new (see software:configurationForConnectingSceneSession
as an alternative).
guard let scene = (scene as? UIWindowScene) else { return }
let window = UIWindow(windowScene: scene)
window.rootViewController = PropertyViewController()
window.makeKeyAndVisible()
}
I’ve tried to initialize the variables in my class, calling my view controller immediately (although I don’t have a xib, and make home optionally available. Nonetheless I don’t need to try this!