Search code examples
iosobjective-crealm

max value of string in realm


I intended to get the max value of string type in Realm by maxOfProperty method as follows:

[[MyRealmObject allObjects] maxOfProperty:propertyName]

However, I encountered the following error:

maxProperty is not supported for string property

Considering I can't change the type of property, what should I do now?


Solution

  • We can use this solution

    [[[[MyRealmObject allObjects] sortedResultsUsingKeyPath:propertyName ascending:NO] firstObject] objectForKeyedSubscript:propertyName];