func isRowSelected(_ row: Int) -> Bool

For TableView: cannot implement this fuction:

func isRowSelected(_ row: Int) -> Bool

{

let selected: Bool

return selected

}

Error message: Constant 'selected' used before being initialized


What is wrong?

Thanks

gefa

Answered by Claude31 in 406555022

*** OOPer explained, the message was very explicit.


What value did you expect the func to return ? true ? false ?

  func isRowSelected(_ row: Int) -> Bool
  {
       let selected: Bool
       return selected
  }


So, you have to keep track somewhere of which row is selected. In an array probably.

Use this array to set the value.

But if you have such an array, why not use it directly, instead of creating another func ?

Shouyld show more code to make it clear.



Don't forget to close all the threads you opened.

In your constant declaration:

       let selected: Bool

It has no initial value.


You cannot use constants or variables before initializing it.


Give it an initial value:

       let selected: Bool = false
Accepted Answer

*** OOPer explained, the message was very explicit.


What value did you expect the func to return ? true ? false ?

  func isRowSelected(_ row: Int) -> Bool
  {
       let selected: Bool
       return selected
  }


So, you have to keep track somewhere of which row is selected. In an array probably.

Use this array to set the value.

But if you have such an array, why not use it directly, instead of creating another func ?

Shouyld show more code to make it clear.



Don't forget to close all the threads you opened.

func isRowSelected(_ row: Int) -> Bool
 
 
Q