CoreData的ReactiveCocoa化尝试 – ReactiveCoreData

ReactiveCoreData(RCD)是一种将Core Data 带入ReactiveCocoa(RAC)世界的尝试。

目前有几个文件包括源代码,Specta规格和一个Mac应用示例。

为了使用它,将该项目源文件从ReactiveCoreData文件夹复制到你的项目中。当然也要把ReactiveCocoa加入到你的项目中。

Mac示例代码:

// This part refetches data for the table and puts it into filteredParents
// It either fetches all Parents or filters by name, if there's something in the search field
// It will also refetch, if objectsChanged send a next
RAC(self.filteredParents) = [[[[Parent findAll]
    where:@"name" contains:filterText options:@"cd"]
    sortBy:@"name"]
    fetchWithTrigger:objectsChanged];

后台进程的另一个示例:

[[[[triggerSignal 
    performInBackgroundContext:^(NSManagedObjectContext *context) {
        [Parent insert];
    }]
    saveContext]
    deliverOn:RACScheduler.mainThreadScheduler]
    subscribeNext:^(id _) {
        // Update UI
    }];

// We can also react to main context's merge notifications to update the UI
[mainContext.rcd_merged 
    subscribeNext:^(NSNotification *note){
        // Update UI
    }];

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:CoreData的ReactiveCocoa化尝试 – ReactiveCoreData