Q:

xcode cannot assign value of type.. to NSSet

I am working on CoreData with Swift 3 and I am almost done. I did the CoreData entities and now I am trying to save data from a form on the app and I got this error:
  import UIKit
  import CoreData

  class ItemDetailsVC: UIViewController, UIPickerViewDelegate,          UIPickerViewDataSource  {

@IBOutlet weak var storePicker: UIPickerView!
@IBOutlet weak var titleField: CustomTextField!
@IBOutlet weak var priceField: CustomTextField!
@IBOutlet weak var detailsField: CustomTextField!

var stores = [Store]()

override func viewDidLoad() {
    super.viewDidLoad()

    storePicker.delegate = self
    storePicker.dataSource = self

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {

    let store = stores[row]
    return store.name
}

func numberOfComponents(in pickerView: UIPickerView) -> Int {

    return 1
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {

    return stores.count
}

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {

    // update
}

func getStores() {
    let fetchRequest: NSFetchRequest<Store> = Store.fetchRequest()

    do {
        self.stores = try context.fetch(fetchRequest)
        self.storePicker.reloadAllComponents()

    } catch {
        // some code
    }

}

@IBAction func savePressed(_ sender: UIButton) {

    let item = Item(context: context)

    if let title = titleField.text {
        item.title = title
    }

    if let price = priceField.text {
        item.price = (price as NSString).doubleValue
    }

    if let details = detailsField.text {
        item.details = details
    }

   item.toStore = stores[storePicker.selectedRow(inComponent: 0)] error:    cannot assign value of type 'Store' to value of type NSSet?

}

I am not asking anyone to solve the error, I just wanna know what the error is telling me to do. Error is on the item.toStore = stores[storePicker... line

A:

The problem is your entity has one-to-many relationship, if you want to fix this issue try to change it "to one". I know you don't want the answer but here is the hint on how you can fix this. If you go to your *.xcdatamodeld file and locate your Item entity you can see the attributes relationships...find appropriate relationship and modify it from "to-many" to "to-one"

