how to create a many to many relationships with core data? Swift, xcode

天涯浪子 提交于 2019-12-02 03:46:45

Person attribute as array of string names of books -- very bad idea!

You need a to-many relationship with the Book entity. That's it.

 Person <------------>> Book

Then, to get an array of book titles for a particular person:

(person.books as! Set<Book>).map { $0.title }

The person can have an additional to-one relationship (e.g. called favoriteBook) to one of the books.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!