I have this code in my init method:
self.monitor = CoreStore.monitorSectionedList(
From<ListEntityType>()
.sectionBy(#keyPath(ListEntityType.muscle.name)) { (sectionName) -> String? in
return "\(String(describing: sectionName)) years old"
}
.orderBy(.ascending(#keyPath(ListEntityType.muscle.name)), .ascending(\.name))
)
I want to somehow add to this monitor .where condition in runtime.
ListEntityType is a type alias of an entity called Exercise. So each Exercise contains one to one relationship Muscle (exercise.muscle).
each entity has unique identifier attribute.
I have array of muscles identifier which I want to use as filter to display object from sectioned list.
How can loop through this identifiers to add then to .where clause to the CoreStore.monitorSectionedList
I probably expect something like this but not 100% sure just assumption:
let predicate = NSPredicate(format: "%K = $ARGUMENT")
var predicates = [NSPredicate]()
if let muscles : [MuscleGroupEntity] = workout?.muscles.toArray() {
for muscle in muscles
{
let myNewPredicate = predicate.withSubstitutionVariables(["ARGUMENT" : muscle.id])
predicates.append(myNewPredicate)
}
}
self.monitor = CoreStore.monitorSectionedList(
From<ListEntityType>()
.sectionBy(#keyPath(ListEntityType.muscle.name)) { (sectionName) -> String? in
return "\(String(describing: sectionName)) years old"
}
.where(format:"%K = %@", argumentArray: predicates)
.orderBy(.ascending(#keyPath(ListEntityType.muscle.name)), .ascending(\.name))
)
this code crashed with error:
-[NSComparisonPredicate rangeOfString:]: unrecognized selector sent to
I guess this is something from predicate I found here, but not sure how to use it correctly in my case
from CoreStore sectioned list monitor how to specify .where clause in runtime
No comments:
Post a Comment