Created
January 8, 2019 19:40
-
-
Save kreeger/0e611302d5993dea6bb5b7635660b2d3 to your computer and use it in GitHub Desktop.
Example data source usage code for the blog post "Flapjack" on O'Reilly's engineering blog.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let dataSourceFactory = CoreDataSourceFactory(dataAccess: dataAccess) | |
let queryAttributes = ["radius": 2.0, "flavor": "Chocolate Chip"] | |
let dataSource: CoreDataSource<Pancake> = dataSourceFactory.vendObjectsDataSource(attributes: queryAttributes, sectionProperty: "flavor", limit: 100) | |
// Prepare yourself for pancakes, but only chocolate chip ones bigger than a 2" radius, and no more than 100. | |
// This block fires every time the data source picks up an insert/change/deletion. | |
dataSource.onChange = { itemChanges, sectionChanges in | |
// If you've added `Flapjack/UIKit` to your Podfile, you get helper extensions! | |
self.tableView.performBatchUpdates(itemChanges, sectionChanges: sectionChanges) | |
// Get a specific pancake: | |
print("\(String(describing: dataSource.object(at: IndexPath(item: 0, section: 0))))") | |
} | |
// Kick off a call to start listening (and immediately fire `.onChange` with all existing results). | |
dataSource.execute() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment