frenzy-ios/Reader/CoreData/Feed+CoreDataClass.swift

31 lines
976 B
Swift
Raw Normal View History

2022-01-09 22:21:27 +00:00
//
// Feed+CoreDataClass.swift
// Reader
//
// Created by Shadowfacts on 1/9/22.
//
//
import Foundation
import CoreData
import Fervor
@objc(Feed)
public class Feed: NSManagedObject {
func updateFromServer(_ serverFeed: Fervor.Feed) {
guard self.id == nil || self.id == serverFeed.id else { return }
self.id = serverFeed.id
self.title = serverFeed.title
self.url = serverFeed.url
self.lastUpdated = serverFeed.lastUpdated
// todo: check this
self.removeFromGroups(self.groups!.filtered(using: NSPredicate(format: "NOT id IN %@", serverFeed.groupIDs)) as NSSet)
let groupsToAddReq = Group.fetchRequest()
groupsToAddReq.predicate = NSPredicate(format: "id IN %@", serverFeed.groupIDs.filter { g in !self.groups!.contains { ($0 as! Group).id == g } })
let groupsToAdd = try! self.managedObjectContext!.fetch(groupsToAddReq)
self.addToGroups(NSSet(array: groupsToAdd))
}
}