0

I'm getting error when i try to extract toolbarStyles from here and create a read-only computed property.

private func toolbarButtons(toolbar: Toolbar) {
     guard let selection = getSelection() else { return }

     var toolbarStyles: [(FormatType, UIButton)] = { //Error: Cannot convert value of type '() -> [Any]' to specified type '[(FormatType, UIButton)]'
       return [
          (.bold, Toolbar.boldButton),
          (.italic, Toolbar.italicButton)
       ]
     }
     
    for (style, button) in toolbarStyles {
      let isEnabled = selection.hasFormat(type: style)

      if isEnabled {
        button.backgroundColor = UIColor.lightGray
        button.setTitleColor(.white, for: .normal)
      } else {
        button.backgroundColor = UIColor.clear
        button.setTitleColor(.systemBlue, for: .normal)
      }
    }
  }
2
  • Remove the = character. Commented May 10, 2022 at 20:43
  • Why use a computed property when you could just put the array into a regular variable? Commented May 10, 2022 at 20:56

0

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.