mercredi 28 juin 2017

If Statements not working in public function? [Swift 3.0 - Xcode]

Im trying to sort out my data by putting on conditions, so I can present it in a table. My condition is that AllData.count must be equal to 4. And even when it is equal to 4, my data doesn't get append to my new array? Can anyone tell me whats going wrong?

var AllData = [String]()
var DataTable = [String]()



public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "cell")

    if AllData.count == 4{
        DataTable.append(contentsOf: AllData)
    print("appended")}
        for i in stride(from: 0, to: DataTable.count - 1, by: 4){
        cell.textLabel?.text = DataTable[i]}
        return(cell)

}


override func viewDidLoad(){



    print("AllData count ------->",AllData.count)
    print("Datatable count---------->",DataTable.count)
    super.viewDidLoad()}

output: AllData count -------> 4 Datatable count----------> 0

Aucun commentaire:

Enregistrer un commentaire