Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func queryFromCollection<T: Codable>(of type: T.Type, query set: Set<UUID>, for key: String) {
- // let objects = await RealmReadService.instance.readObjects(of: type)
- var predicates: [NSPredicate] = []
- for item in set {
- let query = NSPredicate(format: "%K == %@", key, item as CVarArg)
- predicates.append(query)
- }
- let compoundPredicate = NSCompoundPredicate(orPredicateWithSubpredicates: predicates)
- print(compoundPredicate)
- // return objects!.filter(compoundPredicate)
- }
- func queryFromCollection2<T: Codable, S>(of type: T.Type, query set: Set<S>, for key: String) {
- var predicates: [NSPredicate] = []
- for item in set {
- let query = NSPredicate(format: "%K == %@", key, item as! CVarArg)
- predicates.append(query)
- }
- let compoundPredicate = NSCompoundPredicate(orPredicateWithSubpredicates: predicates)
- print(compoundPredicate)
- // return objects!.filter(compoundPredicate)
- }
- func queryFromCollection3<T: Codable, S>(of type: T.Type, query set: Set<S>, for key: String) {
- var predicates: [NSPredicate] = []
- for item in set {
- let query = NSPredicate(format: "%K == %@", argumentArray: [key, item])
- predicates.append(query)
- }
- let compoundPredicate = NSCompoundPredicate(orPredicateWithSubpredicates: predicates)
- print(compoundPredicate)
- // return objects!.filter(compoundPredicate)
- }
- struct CodableStruct: Codable {
- let name: String
- }
- let uuids: Set<UUID> = Set([UUID(), UUID()])
- let test = queryFromCollection(of: CodableStruct.self, query: uuids, for: "name")
- //let test2 = queryFromCollection2(of: CodableStruct.self, query: uuids, for: "name") //Crash
- let test3 = queryFromCollection3(of: CodableStruct.self, query: uuids, for: "name")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement