winner
winner

Reputation: 9

Swift 3 : Core data "data: <fault>" issue

I'm saving the data without any warning, but when I try to get data, I'll get nothing. I don't get what the problem is. I'll check my array and it's giving this warning :

<Sepet: 0x60000028ab40> (entity: Sepet; id: 0xd000000000240000 <x-coredata://5CDE7285-D461-44FD-AA49-DC6C5A61A9D8/Sepet/p9> ; data: <fault>)]

This is my code for saving Core Data :

@IBAction func addToCardAction(_ sender: UIButton) {
        let cell = sender.superview?.superview as! SiparisVerTableViewCell

        if cell.countLabel.text == "0"{
            print("0'dan büyük olmalı")
        }else{

            let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext

            let task = Sepet(context: context)
            task.menuimage = "turk-telekom"
            task.details = cell.detailsTextView.text!

            if cell.detailTextField.text == ""{
                task.customerDetails = "Açıklama yok."
            }else{
                task.customerDetails = cell.detailTextField.text!
            }

            task.count = cell.countLabel.text!
            task.price = cell.priceLabel.text!

            print(cell.menuImageView, cell.detailsTextView.text, cell.detailTextField.text, cell.countLabel.text, cell.priceLabel.text)
            // Save the data to coredata
            print("saved")
            (UIApplication.shared.delegate as! AppDelegate).saveContext()
        }
    }

And this is the code for getting the data and tableView implementation :

func getData() {
    do {
        sepetContents = try context.fetch(Sepet.fetchRequest())
        print(sepetContents)
    }
    catch {
        print("Fetching Failed")
    }
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "sepetCell", for: indexPath) as! SepetTableViewCell
    let sepetim = sepetContents[indexPath.row]


    if let image = sepetim.menuimage, let details = sepetim.details, let customerDetails = sepetim.customerDetails, let price = sepetim.price, let count = sepetim.count {
        cell.menuImageView?.image = UIImage(named: image)
        cell.detailsTextView.text = details
        cell.customerDetailsLabel.text = customerDetails
        cell.priceLabel.text = price
        cell.countLabel.text = count
    }

    return cell
}

Upvotes: 0

Views: 603

Answers (1)

Alistra
Alistra

Reputation: 5195

Fault is nothing bad, it just means that the whole object wasn't loaded from core data, only the basic metadata, this is an optimization measure. Whenever you access properties you need, they will be loaded automatically.

You can of course preload relationships by parametrizing fetch request if you know you gotta need the properties anyway.

What exactly doesn't work? If your problem is that the object doesn't print fully in the debugger, it is unfortunately how it is, LLDB doesn't unfault objects.

Upvotes: 3

Related Questions