I'm gettiing a fatal error and i don't know why. i have tried changing the '!' with '?' at _title but it still don't work.
class Post: NSObject, NSCoding {
private var _img: String!
private var _title: String!
private var _descLbl: String!
var img: String {
return _img
}
var titleLbl: String {
return _title
}
var descLbl: String {
return _descLbl
}
init(imagePath: String, title: String, description: String) {
self._img = imagePath
self._title = title
self._descLbl = description
}
}
Here is where i get the error:
fatal error: unexpectedly found nil while unwrapping an Optional value
class PostCell: UITableViewCell {
@IBOutlet weak var postImg: UIImageView!
@IBOutlet weak var title: UILabel!
@IBOutlet weak var descLbl: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
func configureCell(post: Post) {
title.text = post.titleLbl //Here i get the error
descLbl.text = post.descLbl
}
}
Here i call the function configureCell in ViewController:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let post = posts[indexPath.row]
if let cell = tableView.dequeueReusableCellWithIdentifier("postCell") as? PostCell {
cell.configureCell(post)
return cell
}else{
var cell = PostCell()
cell.configureCell(post)
return cell
}
}