A sort descriptor for a (SQLite based) Core Data fetch request can only use persistent attributes and a limited set of built-in selectors, but not Objective-C methods like
integerValue
.
In this case, it seems that the integerValue
is just ignored, so that the from
values
are sorted as strings, and not as numbers.
If you cannot change the attribute type to "Integer" (which would solve the problem as well) then you can use a special selector as a workaround:
NSSortDescriptor *mySortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"from"
ascending:YES
selector:@selector(localizedStandardCompare:)];
localizedStandardCompare
is the "Finder-like sort" and sorts strings containing digits
according to their numerical value.