Using Comparable Protocol in Models


#1

I wanted to use ‘Comparable’ Protocol on my Realm Model ‘Activity’ so that I can use my custom sorting on the ‘Results’
But I get following exception:

'RLMException', reason: 'Cannot sort on key path 'self': property 'ActivityObject.self' does not exist.'
Following is the sorting function.

static func < (lhs: Activity, rhs: Activity) -> Bool {
        if lhs.week > rhs.week{
            return true
        }else if lhs.week < rhs.week{
            return false
        }else if lhs.week == rhs.week{
            return lhs.day > rhs.day
        }
        return false
    }

#2

Can you share the code where you do the actual sorting ?