我需要能够将#keypath 传递给一个函数来过滤我的CoreData 记录。
我这样做:
func filteredExercises(with propertyKeyPath: #keyPath, filter: Any) {
do {
let filteredExercises = try CoreStore.fetchAll(
From<ExerciseEntity>(),
Where<ExerciseEntity>("%K = %@", #keyPath(ExerciseEntity.muscle.name), filter)
)
} catch {
}
}
但是可以肯定 #keyPath 不是类型,如何正确执行?或者我是否需要准备一个过滤后的字符串,我将把它传递给一个像谓词一样的函数?