Question: ```
func fetchCD() -> [Entity] {

  var options : [Entity] = []
  let fetchRequest = NSFetchRequest(entityName:"EntityName")

  do {
    options = try cdh.managedObjectContext.executeFetchRequest(fetchRequest) as! [Entity]
  } catch let error as NSError {
    print("Fetch failed: \(error.localizedDescription)")
  } catch {

  }

  //here I'd like to order by Entity.types.counter (desc) 

  return options
}

//Entity+CoreDataProperties.swift
extension Entity {
    //my values
    @NSManaged var types: NSSet?
}

//Type+CoreDataProperties.swift

extension Type {

@NSManaged var counter: NSNumber

}

```

How I'd sort my [Entity] array by conter which is a property on Type entity (has a many relationship with Entity) ?

Answer: 
Short answer is you can't because it doesn't make any sense. You are wanting to sort a single object based on many objects.

Now if you wanted to sort `EntityName` based on the highest `Type` or the largest `Type` then that would be a different question and a solvable problem.

To sort requires a consistent answer to the question of "value". What value should `EntityName` be sorted on when the many `Type` objects are inspected? 

Should it be based on the quantity of `Type` objects? That could be sorted. 

Should it be based on the existence of `Type` objects? That could be sorted as well.

You could also turn that around and fetch all of the `Type` entity objects, sort them based on `counter` and then retrieve the `EntityName` object that is associated with the `Type` entity after the sort is complete. Then your code would look like this:

```
func fetchCD() -> [Entity] {

  let fetchRequest = NSFetchRequest(entityName:"Type")
  fetchRequest.sortDescriptors = [NSSortDescriptor("counter", ascending: true)]

  do {
    let results = try cdh.managedObjectContext.executeFetchRequest(fetchRequest) as! [Type]
    let options = results.map($0.entity) as! [Entity]
    //Type is already sorted
    return options
  } catch {
    fatalError("Fetch failed: \(error)")
  }
}

```

This code is **NOT** 100% as I do not have access to your project and I would not name my entities like this. But for demonstration purposes it shows you an option.
If its an accessible value, you can use `sortInPlace` to sort the array.

You just have to specify how to access the value, and how to compare it, I think you can just call like this, check if it help you.

```
options.sortInPlace({ $0.types.counter < $1.types.counter })

```