Swift: Core data trouble with to-many relationship and mutableOrderedSetValueForKey -


i'm having trouble understanding why ordered set saving 1 entry.

my code follows:

let newinovice = nsentitydescription.insertnewobjectforentityforname("invoice", inmanagedobjectcontext: managedobjectcontext) as! invoicemo  let itemdetail = nsentitydescription.insertnewobjectforentityforname("invoicedetail", inmanagedobjectcontext: managedobjectcontext) as! invoicedetailmo      // data entry      // add invoice number invoice     newinovice.invoicenumber = getinvoicenum()     newinovice.date = invoicedate     // create mutable set add details     items in details {         itemdetail.detail = items[propkeys.itemdescription]         let item = items[propkeys.itemprice] ?? "0"         let itemdouble = {  return double(item) ?? 0  }()         itemdetail.price = itemdouble         let quantity = items[propkeys.itemquantity] ?? "1"         let quantityint = {  return int(quantity) ?? 0  }()         itemdetail.quantity = quantityint         print("this item detail before insertion: \(itemdetail)")         newinovice.mutableorderedsetvalueforkey("invoicedetails").addobject(itemdetail)         subtotal += itemdouble * double(quantityint)     }     print("details.count = \(details.count)")     print("start mutable  \(newinovice.invoicedetails?.count) end mutable set")       // save data     {         try newcustomer.managedobjectcontext?.save()     } catch {         print(error)     } 

i've read through docs , seems i'm doing correctly adds 1 entry ordered set though i've iterated through array of objects.

here debugger showing entries before added , count of managed object after adding objects. debuggerwindow

my relationships set follows: relationships

you creating 1 invoicedetail outside for loop. obviously, have create 1 each detail contained in data array.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -