Cannot convert value of type '() -> [Any]' to specified type '[(TextFormatType, UIButton)]'

349 views Asked by At

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)
      }
    }
  }
0

There are 0 answers