{"id":16482799,"url":"https://github.com/shaps80/uitableview-datasource","last_synced_at":"2025-07-10T13:34:04.233Z","repository":{"id":9621504,"uuid":"11548902","full_name":"shaps80/UITableView-Datasource","owner":"shaps80","description":"Some convenience classes for dealing with UITableView datasources for collections, CoreData and search results.","archived":false,"fork":false,"pushed_at":"2013-07-20T15:39:37.000Z","size":164,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-28T22:41:40.655Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shaps80.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-07-20T15:26:31.000Z","updated_at":"2017-06-17T01:26:43.000Z","dependencies_parsed_at":"2022-09-15T09:43:52.068Z","dependency_job_id":null,"html_url":"https://github.com/shaps80/UITableView-Datasource","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/shaps80/UITableView-Datasource","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaps80%2FUITableView-Datasource","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaps80%2FUITableView-Datasource/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaps80%2FUITableView-Datasource/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaps80%2FUITableView-Datasource/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shaps80","download_url":"https://codeload.github.com/shaps80/UITableView-Datasource/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaps80%2FUITableView-Datasource/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264585371,"owners_count":23632647,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T13:12:04.649Z","updated_at":"2025-07-10T13:34:04.214Z","avatar_url":"https://github.com/shaps80.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"UITableView-Datasource\n======================\n\nSome convenience classes for dealing with UITableView datasources for collections, CoreData and search results.\n\nSo I thought about it and decided to try and build something into my Snippex library whereby the datasource would be a separate class altogether..\n\nWhat I ended up with was an abstract class that does all the common things, like cell creation, predicate and sorting management and also some animation stuff.\nThen I used that to create a coreData subclass, a collection (array) subclass and a search (UISearchResultsController) subclass.\n\nNow its really easy to use! Existing storyboard, no subclassing required and no setup. Just copy in the files and implement it with an existing UITableViewController. Best thing is you can swap between types really easily too, in fact you don’t even need a UITableViewController subclass in many instances..  You could write all the code in your AppDelegate or some other file and just assign the datasource from there. \n\nThis is awesome because it means using the same datasource, cells, etc.. for multiple screens/tables is mostly 1 line of code per controller.\n\nThere’s about 100 lines in that TableViewController class and a bunch of files, but if you look carefully you’ll see that I’ve included some other SPX files that are NOT required for these new datasources to work, they are their for my convenience. :)\nThe datasource class is the only group you need to take into a new project to use these classes.\n\n__Blocks__\n\nWell, I wanted to be able to provide the cells and their config from the controller, since this class would normally know about the original object logic, so that’s why the cell are provided through blocks.\n\nFor the search I needed a way to provide the source every time its presented, because the data may have changed since it was last loaded. This allows me to request the source in its current state right before display.\n\nThe other useful block is the search one. This allow you to get a hold of the current searchString and provide your own predicate since I don’t know which field you want to search against. :)\n\n__Example__\n\nFirst lets define our sort descriptors\n\n\t-(NSArray *)sortDescriptors\n\t{\n\t    return @[ [NSSortDescriptor sortDescriptorWithKey:@\"name\" ascending:YES] ];\n\t}\n\t\nAlso, lets's add a method to provide our cells for both datasources \n**Note we use [weakSelf tableView] because the UISearchResultsController's tableView doesn't have its cell identifier's set\n\n\t-(void)configureCellForDataSource:(SPXDatasource *)datasource\n\t{\n\t    id __weak weakSelf = self;\n\n\t    [datasource setCellForRowAtIndexPathBlock:^\n\t     UITableViewCell *(UITableView *tableView, id object, NSIndexPath *indexPath)\n\t    {\n\t        // we have to use self.tableView here since that's the tableView with its cell identifier's set\n\t        UITableViewCell *cell = [[weakSelf tableView] dequeueReusableCellWithIdentifier:@\"Cell\"];\n\t        cell.textLabel.text = [object valueForKey:@\"name\"];\n\t        return cell;\n\t    }];\n\t}\n\nNext, lets define our main tableView datasource\n\n\t-(void)configureCoreDataSource\n\t{\n\t    // get a new coreData based datasource\n\t    _coreDataSoure = [SPXCoreDataDatasource dataSourceForTableView:self.tableView\n\t                                                           context:self.managedObjectContext\n\t                                                        entityName:self.entityName];\n\n\t    // configure its sortDescriptors\n\t    [_coreDataSoure setSortDescriptors:[self sortDescriptors]];\n\n\t    // configure the cells for this datasource\n\t    [self configureCellForDataSource:_coreDataSoure];\n\t    [self.tableView setDataSource:_coreDataSoure];\n\t}\n\nNow, let's define our search datasource\n\n\t-(void)configureSearchDataSource\n\t{\n\t    // get a new search based datasource\n\t    _searchDataSource = [SPXSearchDatasource dataSourceForSearchDisplayController:self.searchDisplayController];\n\n\t    // configure its sortDescriptors\n\t    [_searchDataSource setSortDescriptors:[self sortDescriptors]];\n\n\t    id __weak weakSelf = self;\n\t    [_searchDataSource setSourceWithBlock:^NSArray *\n\t    {\n\t        return [[weakSelf coreDataSoure] source];\n\t    }];\n\n\t    // configure how the search will be handled\n\t    [_searchDataSource setSearchPredicate:^NSPredicate *(NSString *searchString)\n\t    {\n\t        return [NSPredicate predicateWithFormat:@\"SELF.name contains[c] %@\", searchString];\n\t    }];\n\n\t    // configure the cells for this datasource\n\t    [self configureCellForDataSource:_searchDataSource];\n\t    [self.searchDisplayController setSearchResultsDataSource:_searchDataSource];\n\t}\n\t\nFinally let's load everything up...\n\t\n\t-(void)viewDidLoad\n\t{\n\t    [super viewDidLoad];\n\n\t    [self configureCoreDataSource];\n\t    [self configureSearchDataSource];\n\t}\n\t\n__Summary__\n\nOf course the search datasource may not be required at all, but you can see how little code is required in order to get this working and completely hooked up to CoreData :)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshaps80%2Fuitableview-datasource","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshaps80%2Fuitableview-datasource","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshaps80%2Fuitableview-datasource/lists"}