Ho creato un modello di dati in questo modo:risparmio, la cancellazione e il recupero dei dati da uno a molti dati fondamentali di relazione
ho questo codice per una richiesta di recupero:
func roundFetchRequest() -> NSFetchRequest {
let fetchRequest = NSFetchRequest(entityName: "Customer")
print("Check here: \(myRoundIndexPath)")
//let predicate : NSPredicate = NSPredicate(format: "custRoundRel = %@", frc2.objectAtIndexPath(myRoundIndexPath!) as! RoundName) //ASSUME THIS IS CORRECT
let sortDescriptor = NSSortDescriptor(key: "c2fna", ascending: true)
//fetchRequest.predicate = predicate
fetchRequest.sortDescriptors = [sortDescriptor]
return fetchRequest
}
Il mio codice commentato non dà un errore, ma non riesco a salvare un cliente nell'istanza RoundName. Quando salvi un cliente con i suoi attributi, ho utilizzato questo codice:
func newCust() {
let cont = self.context
let newCustomer = NSEntityDescription.entityForName("Customer", inManagedObjectContext: cont)
let aCust = Customer(entity: newCustomer!, insertIntoManagedObjectContext: cont)
aCust.c2fna = firstName.text
aCust.c3lna = lastName.text
aCust.c4tel = tel.text
aCust.c5mob = mob.text
aCust.c6ema = email.text
aCust.c7hsn = houseNo.text
aCust.c8fir = street.text
aCust.c9sec = secondLine.text
aCust.c10ar = area.text
aCust.c11pc = postcode.text
aCust.c12cos = cost.text
aCust.c13fq = frequencyNumber.text
aCust.c14fqt = frequencyType.text
let DF = NSDateFormatter()
aCust.c15das = DF.dateFromString(startDate.text!)
//Do Pics in a minute & next date in a minute
aCust.c17notes = notes.text
//print("Desc = \(picRound.image?.description)")
do {
try context.save()
print("Save Successful")
} catch {
print("Save Unsuccessful")
}
}
Qual è il codice per collegare questo cliente al Round corretto?
Grazie, sono molto nuovo per i dati di base e apprezzerei davvero qualsiasi aiuto.
Grazie a @Wain, così quando salvi un'entità cliente con i relativi attributi come faccio a collegarlo al nome del round corretto? – agf119105
è necessario avere quell'istanza 'Round', o già o recuperarla per nome, quindi basta impostarla sulla relazione:' yyyy.custRoundRel = xxxx' (dove 'yyyy' è la tua nuova istanza' Cliente' – Wain