0

I have created a core data model like below

Songs Core Data Attribute

Songs Core Data Relationship

Playlists Core Data

I have use this as code to pull from Core Data and arrange it with Alphabetical order.

let PlaylistTable = (PlaylistTables![0] as AnyObject).value(forKey: "songs") as! NSSet

let songsUnsorted = PlaylistTable.allObjects as NSArray
return songsUnsorted.sortedArray(using: [songSortDescriptor]) as NSArray

How can i do to allows songs to be rearrange in the order i like ? Example

a
b
c

To whatever arrangement i like and next time when i pull from Core Data it will be the same order ?

b
c
a
rmaddy
  • 314,917
  • 42
  • 532
  • 579
WT24
  • 43
  • 1
  • 6
  • not sure but maybe using `NSMutableOrderedSet` for the attribute in the Playlist class and its relationship in the xcdatamodel to ordered could be a good start ? – James Woodrow Sep 22 '18 at 01:51

1 Answers1

0

You need to add an attribute that will function as an index. That way, when you fetch, you ask for a sort descriptor that sorts on that attribute.

matt
  • 515,959
  • 87
  • 875
  • 1,141