0

This should be super straightforward. Here's what I am trying to do:

class ViewController: UIViewController{
    var leftBarButton: UIButton;
    var rightBarButton: UIButton;

    override func viewDidLoad() {
        super.viewDidLoad()
    }
}

But I am getting an error that viewController has no initializers. I know I need to give the variables default values, so I tried:

var rightBarButton: UIButton(type: UIButtonType.System) as UIButton;

But that's giving me an error about multiple declarations.

1 Answer 1

1

You need something like this

var rightBarButton: UIButton = UIButton(type: UIButtonType.System)

You need to intialize the button, but if you're not planning to change it I suggest you change it to let

Sign up to request clarification or add additional context in comments.

2 Comments

or more succinctly: var rightBarButton = UIButton(type: .System)
Yup. Though he'll probably need a constant button, so: let rightBarButton = UIButton(type: .System)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.