skip to Main Content

I tried to do

var title = [String]()

but an error popped up: Property ‘title’ with type ‘[String]’ cannot override a property with type ‘String?’

How to fix?

have also tried directly

var title = ["a", "b", "c"] and got same error

2

Answers


  1. Variable name title is reserved as String it’s a property inside the base class UIViewController make it another name like

    var titles = [String]()
    

    Check title

    Login or Signup to reply.
  2. its namespace error, you already have property with same name in yore class or yore parent class
    for example:

    Wrong:

    class Example {
       let first: String
       let first: [String]
    }
    

    correct:

    class Example {
       let first: String
       let second: [String]
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search