i work with core data and swift 3 for macOS.
- i have to entities: Person and Books
- I can create a person
- i can create a book which will assign to a person
- and i know how i can get the information which book is assign to which person with this code at the end
but how can i get the information which person has which book?
more details in my last post: swift 3 - create entry with relationship
Thank you very much :)
let appdelegate = NSApplication.shared().delegate as! AppDelegate
let context = appdelegate.persistentContainer.viewContext
var books = [Book]()
let request = NSFetchRequest<NSFetchRequestResult>(entityName: "Book")
do {
books = try context.fetch(request) as! [Book]
} catch { }
for book in books {
print("Title: \(book.title!)")
print("Person: \(book.person!.name!)")
}