I get an Error after adding a NSData variable to my Realm Model:
fatal error: unexpectedly found nil while unwrapping an Optional value
This Error doesn't appear when im not using the NSData value.
This is my simple Item (Item.swift)
class Item: Object {
dynamic var Name: String = ""
dynamic var Adress:String = ""
dynamic var image: NSData = NSData()
}
I get this Error, at return dataSource.Count :
var dataSource: Results<Item>!
let itemDetailSegue = "showItemDetail";
var loadCurrentItem: Item!
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
reloadTable()
}
override func viewDidLoad() {
super.viewDidLoad()
reloadTable()
}
// MARK: - Table view data source
func reloadTable(){
do{
let realm = try Realm()
dataSource = realm.objects(Item)
tableView?.reloadData()
}catch{
print("ERROR ReloadTable")
}
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataSource.count
}