What is the useful difference between these two formats:
request.sortDescriptors = [NSSortDescriptor(key:"dateCreated", ascending: false)]
and
request.sortDescriptors = [NSSortDescriptor(key: #keyPath(Note.dateCreated), ascending: false)]
In the second format #keyPath is confusing to me. What exactly it is and where I can read more about this?
There is no difference between
and
both will do the sort with
Noteobject'sdateCreatedproperty the latter has an advantage of avoiding hard coding problems e.x writingdatCreatedinstead ofdateCreatedwill throw a compile time error , so it'll safely avoid run-time crashes that definitely will happen with the former under same circumstanceshttps://www.klundberg.com/blog/swift-4-keypaths-and-you/
http://chris.eidhof.nl/post/sort-descriptors-in-swift/