0
votes

iam a swift beginner, i wanna code a little app for me and i have a problem with it. My app has three entities (Templates, Records and Positions), here you can see:

Datamodel

At one part of the app i can add new Records and for that Record i add some Positions (xpos and ypos).

At a part I have a tableview were i list my Records. Now i wanna click one Record in the table and i want to get all Position-Attributes linked with the particular selected Record.

With that code i can get all xpos-Positions but how can i get a single xpos? :)

guard let moc = self.managedContext else {
   return
}

let fetchRequest: NSFetchRequest<Records> = Records.fetchRequest()

do {
   let searchResults = try moc.fetch(fetchRequest)
   let xpos = searchResults[0].positions?.mutableArrayValue(forKey: "xpos")
   print(xpos)
} catch {
   print("Error with request: \(error)")
}
1

1 Answers

0
votes

You want to look into using NSPredicate. NSPredicate basically lets you define the conditions which the record needs to meet to be included in the results. Think of it as a filter if you will.

fetchRequest.predicate = NSPredicate(format: "uniqueID = %@", arugments:...)