In a mileage-tracking app I am developing, the concepts include "Places," "Legs," and "Routes." Essentially, a Route is a collection of connected Legs, where each Leg is simply a straight line between two Places (with an associated distance).
I am having a problem modeling the Route-Leg relationship in Core Data because a Route may include the same Leg twice or more. For example, a person could travel Home to Office, Office to Worksite, Worksite to Home, Home to Office, and Office to Home as a single, contiguous path of travel on a given day. In that case, the "Home-to-Office" Leg is contained twice in the Route. But Core Data creates the To-Many relationship in a NSManagedObject subclass as an instance of NSOrderedSet, which does not permit duplicate Legs.
Is there a way I can create a relationship between the two Core Data-backed objects (Route and Leg) that allows multiple occurrences of the same Leg in a single Route? I am developing my app in Swift, so any Swift-specific suggestions would be appreciated.
Thank you.