简体   繁体   English

核心数据:如何创建播放列表并从数据库添加歌曲?

[英]Core data: How do I create playlist and add songs from a database?

I am working on this core data app, and im not exactly shure how to do what i want. 我正在开发此核心数据应用程序,而我不确定该怎么做。

Right now my first view displays a list of playlists. 现在,我的第一个视图显示播放列表的列表。 I can add a playlist to the list. 我可以将播放列表添加到列表中。 The plus sign pops up addViewController. 加号会弹出addViewController。 From here i can add a name to the playlist, now comes the tricky part for me.. 从这里我可以在播放列表中添加一个名称,现在对我来说是棘手的部分。

I want to be able to select songs from a big list i have. 我希望能够从一个很大的列表中选择歌曲。

How do i set up this models? 如何设置此模型?

I was thinking something like this: 我在想这样的事情:

|Entity: Playlist | |实体:播放列表| |Entity: Song | |实体:歌曲|
|Attribute: name | |属性:名称| |Attribute: name | |属性:名称|
|Relationship: songs |<<------------->>|Relationship: playlists | |关系:歌曲| << ------------- >> |关系:播放列表|

I want songs to be in more than one playlist, sometimes more than once in a playlist, and I want to be able to add more songs to the database. 我希望歌曲在多个播放列表中,有时在一个播放列表中包含多个歌曲,并且希望能够将更多歌曲添加到数据库中。

Anyone know some sample code that does this sort of thing, or give me some hints at how to do this? 任何人都知道执行此操作的示例代码,或者给我一些有关如何执行此操作的提示?

Adding a song to a playlist more than once is a bit tricky. 多次将歌曲添加到播放列表有点棘手。 First of all within a relationship you can define only one relation between two objects. 首先,在一个关系中,您只能定义两个对象之间的一个关系。 Second you need to define some kind of sort index for multiple positions within a playlist 其次,您需要为播放列表中的多个位置定义某种排序索引

I would recommend adding another entity handling the relation between song and playlist (see image below, the sort index in Playlist is optional) Playlist - SongInPlaylist - Song http://www.freeimagehosting.net/uploads/4a9b2fbea4.png 我建议添加另一个实体来处理歌曲和播放列表之间的关系(请参见下图,播放列表中的排序索引是可选的) 播放列表-SongInPlaylist-歌曲http://www.freeimagehosting.net/uploads/4a9b2fbea4.png

I did add NSFetchedResultsControllerDelegate to a new view and send the song at the selected row to the playlist. 我确实将NSFetchedResultsControllerDelegate添加到新视图,并将选定行的歌曲发送到播放列表。 Works fine now! 现在工作正常! thanks for the answer! 感谢您的回答!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM