my app is crashing and show this class is not key value coding-compliant for the key tableView using swift

This function gets variables from another file users.swift

append data

func getData(salval:String )
{   self.tabArray.removeAll()
    ref = Database.database().reference()
    let userID = Auth.auth().currentUser!.uid
    if salval != "" {
        ref?.child("Schedule").child("Codaphic").child(salval).child(userID).observe(.childAdded, with: { (snapshot)
            in
            if  let dictionary = snapshot.value as? [String : AnyObject]
            {
                let user = users()
                user.setValuesForKeys(dictionary)
                self.tabArray.append(user)
                self.tableView1.reloadData()
            }
          
            
        })
    }
    
}

This is users.swift

import UIKit
class users : NSObject
{   
 var cname : String?
var _logi: String?
var key : String?
var wname : String?
var address : String?
var endtime : String?
var _leti : String?
var starttime : String?
var date : String?
var groupname : String?
var month : String?

}

this file is inherited with NSObject but when project debugging its show error

Upvotes: 1

Views: 125

Answers (1)

Daniel Dramond
Daniel Dramond

Reputation: 1598

If you're using user.setValuesForKeys(dictionary) it means that the variables in your User class MUST match the same names as the ones in your database. The safest way is to remove user.setValuesForKeys(dictionary) and use:

let user = User()
user.cname = dictionary["cname"] as? String
user.date = dictionary["data"] as? String

etc...

Upvotes: 2

Related Questions