Descriptors - seeking further understanding


Hi there,

I was hoping someone could help me to better understand how descriptors work. At the moment their operation seems like somewhat of a blackbox to me

  1. From the reading the book my understanding is that descriptors are:
  • Used to sort arrays
  • Objects that represent a property of another object (e.g. either a variable like last name or a value returned by a method)
  1. What is not clear to me is the following:
  • Why are we passing sortUsingDescriptors an array? Is it simply because we are using multiple descriptor objects to perform the sort? What would you pass if you are just sorting using a single descriptor?
  • What is actually happening when the sort descriptor gets applied? is it running through the employees array and sorting objects depending on the value returned by their valueOfAssets method? … and then running through a second time and sorting based on each objects employeeID (where asset values for two objects are the same?)
  • How does the sortDescriptorWithKey method know that employeeID is a variable and that valueOfAssets is a method that returns a value, simply by passing it a string object e.g. @“valueOfAssets”

Sorry if these questions seem a bit thick! This is my first language so I’m literally a few days into the coding journey and trying not to get overwhelmed