I am following a youtube tutorial and replacing the content to fit my firebase database for the project but I can't figure out why I am getting "Unexpectedly found nil while unwrapping an Optional value" error at this point.
I have bolded the line where the error occurs, and as you can see I have a print statement right above it, and this produces the desired results so its not NIL but why is this message coming?
import UIKit
import Firebase
class firstViewViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableViewer: UITableView!
var refPlayer = DatabaseReference()
var playerList = [PlayerModel]()
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return playerList.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableViewer.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! labelviewCell
let player: PlayerModel
player = playerList[indexPath.row]
print(player.navn)
**cell.labelOne.text = player.navn**. // HERE IS THE ERROR
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
FirebaseApp.configure()
refPlayer = Database.database().reference().child("Player");
refPlayer.observe(DataEventType.value, with: {(snapshot) in
if snapshot.childrenCount > 0 {
self.playerList.removeAll()
for players in snapshot.children.allObjects as! [DataSnapshot]{
let playerOject = players.value as? [String: AnyObject]
// let playerId = playerOject?["id"]
let playerName = playerOject?["navn"]
let playerweek = playerOject?["uke"]
// let playerPlayed = playerOject?["spillet"]
// let playerExtra = playerOject?["extra"]
// let playerWalkover = playerOject?["walkover"]
// let playerKommentar = playerOject?["kommentar"]
let player = PlayerModel(//id: playerId as! String,
navn: (playerName as! String?)!,
uke: (playerweek as! String?)!
// spillet: (playerPlayed as! String?)!,
// extra : (playerExtra as! String?)!,
// walkover: (playerWalkover as! String?)!,
// kommentar: (playerKommentar as! String?)!
)
self.playerList.append(player)
}
self.tableViewer.reloadData()
}
})
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}