NSFetchedResultsController - 排序为数字但字符串字段
NSFetchedResultsController - sort as a number but string field
我正在从获取请求中返回一些数据,该字段存储为字符串。我想做的是对结果进行排序,使数字有序
let sortDescriptor = NSSortDescriptor(key: "number", ascending: true)
fetchRequest.sortDescriptors = [sortDescriptor]
我要的顺序是 1,2,3,100, 200, 1544, White
实际字符串的开头或结尾并不重要( End 是首选但不需要)
1, 100, 1544, 2, 3, 白色
var sortDescriptor = NSSortDescriptor(key: "title", ascending: true,
selector: #selector(NSString.localizedStandardCompare))
fetchRequest.sortDescriptors = [sortDescriptor]
我正在从获取请求中返回一些数据,该字段存储为字符串。我想做的是对结果进行排序,使数字有序
let sortDescriptor = NSSortDescriptor(key: "number", ascending: true)
fetchRequest.sortDescriptors = [sortDescriptor]
我要的顺序是 1,2,3,100, 200, 1544, White 实际字符串的开头或结尾并不重要( End 是首选但不需要)
1, 100, 1544, 2, 3, 白色
var sortDescriptor = NSSortDescriptor(key: "title", ascending: true,
selector: #selector(NSString.localizedStandardCompare))
fetchRequest.sortDescriptors = [sortDescriptor]