这就是我现在的定义方式:
protocol FetchedResultsControlable {
var fetchedResultsController: NSFetchedResultsController<NSManagedObject>? { get set }
}
为了遵循该协议,我需要做些什么:
var fetchedResultsController: NSFetchedResultsController<Thread>?
var fetchedResultsController: NSFetchedResultsController<Task>?
var fetchedResultsController: NSFetchedResultsController<Notification>?
我该如何实现?
这就是我要使用的方式。只需扩展其他协议即可:
protocol NotificationsViewModelable: FetchedResultsControlable {
var notifications: [Notificationable] { get }
}
class NotificationsViewModel: NotificationsViewModelable {
var notifications: [Notificationable] {
return fetchedResultsController?.fetchedObjects ?? []
}
var fetchedResultsController: NSFetchedResultsController<Notification>?
}