how to map one JSON property to two fields, with a transformation? (needed for a simple NSSortDescriptor)

13 views
Skip to first unread message

Dan Morrow

unread,
May 28, 2015, 12:12:14 PM5/28/15
to res...@googlegroups.com
OK, here's the situation...

I'm getting a list of objects that contain titles.

When I display these objects, I'd like to display them using "title sorting", meaning that I'd like to sort without concern for leading "a" "an" and "the"

All my data is cached to a local CoreData database, and I'm using an NSFetchedResultsController to get my data.

The problem is that I cannot use a custom NSSortDescriptor with a block, b/c CoreData won't allow that.

So, what I'd like to do is set up a mapping, so that one JSON value gets mapped to 2 object-properties. Since we're talking about titles here, the 2 properties would be "displayTitle" and "sortableTitle".

So if my JSON looks like this:

{
  "title" : "The Great Big Title"
}


My object would look like this:
{
 "displayTitle" : "The Great Big Title",
 "sortableTitle" : "Great Big Title"
}

This data would get written to CoreData, and then I can create an NSSortDescriptor that can be used by my NSFetchedResultsController, and display the objects in their proper order.

Thanks for any help in this.
Reply all
Reply to author
Forward
0 new messages