Giter Club home page Giter Club logo

datasource's Introduction

DATASource

If you are not familiarized with NSFetchedResultsController, it allows you to efficiently manage the results returned from a Core Data fetch request to provide data for a UITableView or a UICollectionView. NSFetchedResultsController monitors changes in Core Data objects and notifies the view about those changes allowing you to be reactive about them.1

Using NSFetchedResultsController and NSFetchedResultsControllerDelegate is awesome, but sadly it involves a lot of boilerplate. Well, luckily with DATASource not anymore.

  • Encapsulates NSFetchedResultsController and NSFetchedResultsControllerDelegate boilerplate
  • Supports indexed tables out of the box
  • Supports sectioned collections out of the box
  • Swift
  • Objective-C compatibility

Table of Contents

UITableView

Basic Usage

Hooking up your table view to your Task model and making your UITableView react to insertions, updates and deletions is as simple as this.

Swift:

lazy var dataSource: DATASource = {
    let request: NSFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "Task")
    request.sortDescriptors = [NSSortDescriptor(key: "title", ascending: true)]

    let dataSource = DATASource(tableView: self.tableView, cellIdentifier: "Cell", fetchRequest: request, mainContext: self.dataStack.mainContext, configuration: { cell, item, indexPath in
        cell.textLabel?.text = item.valueForKey("title") as? String
    })

    return dataSource  
}()

override func viewDidLoad() {
  super.viewDidLoad()

  self.tableView.dataSource = self.dataSource
}

Objective-C:

NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Task"];
request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"title" ascending:YES]];

DATASource *dataSource = [[DATASource alloc] initWithTableView:self.tableView
                                                cellIdentifier:@"Cell"
                                                  fetchRequest:request
                                                   mainContext:self.dataStack.mainContext
                                                   sectionName:nil
                                                 configuration:^(UITableViewCell * _Nonnull cell, NSManagedObject * _Nonnull item, NSIndexPath * _Nonnull indexPath) {
                                                     cell.textLabel.text = [item valueForKey:@"name"];
                                                 }];

self.tableView.dataSource = dataSource;

Sectioned UITableView

DATASource provides an easy way to show an sectioned UITableView, you just need to specify the attribute we should use to group your items. This attribute is located in the dataSource initializer as a parameter called sectionName.

Check the TableViewControllerWithSections Demo for an example of this, were we have an sectioned UITableView of names, where each section is defined by the first letter of the name, just like the Contacts app!

Sectioned UITableView Without Indexes

You can disable the indexes by overwritting the method that generates them and just return an empty list of indexes. Add the DATASourceDelegate protocol to your controller then implement the sectionIndexTitlesForDataSource:dataSource:tableView method, like this:

self.dataSource.delegate = self

extension MyController: DATASourceDelegate {
    func sectionIndexTitlesForDataSource(dataSource: DATASource, tableView: UITableView) -> [String] {
        return [String]()
    }
}

Custom Headers

By default DATASource uses the UITableView's built-in header. But many apps require the use of custom headers when using sectioned table views. To be able to use your custom header view, you will need to disable the built-in header by implementing dataSource:tableView:titleForHeaderInSection: in the DATASourceDelegate so it returns nil:

self.dataSource.delegate = self

extension MyController: DATASourceDelegate {
    func dataSource(dataSource: DATASource, tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        return nil
    }
}

DATASource also provides a simple method to get the title for an specific section, useful when dealing with custom headers.

let sectionTitle = self.dataSource.titleForHeaderInSection(section)

UITableViewDataSource

DATASource takes ownership of your UITableViewDataSource providing boilerplate functionality for the most common tasks, but if you need to override any of the UITableViewDataSource methods you can use the DATASourceDelegate.

UICollectionView

Basic Usage

Hooking up a UICollectionView is as simple as doing it with a UITableView, just use this method.

Swift:

let request: NSFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "Task")
request.sortDescriptors = [NSSortDescriptor(key: "title", ascending: true)]

let dataSource = DATASource(collectionView: self.collectionView, cellIdentifier: "Cell", fetchRequest: request, mainContext: self.dataStack.mainContext, configuration: { cell, item, indexPath in
    cell.textLabel.text = item.valueForKey("title") as? String
})

collectionView.dataSource = dataSource

Objective-C:

NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Task"];
request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"title" ascending:YES]];

DATASource *dataSource = [[DATASource alloc] initWithCollectionView:self.collectionView
                                                     cellIdentifier:CollectionCellIdentifier
                                                       fetchRequest:request
                                                        mainContext:self.dataStack.mainContext
                                                        sectionName:nil
                                                      configuration:^(UICollectionViewCell * _Nonnull cell, NSManagedObject * _Nonnull item, NSIndexPath * _Nonnull indexPath) {
                                                          CollectionCell *collectionCell = (CollectionCell *)cell;
                                                          [collectionCell updateWithText:[item valueForKey:@"name"]];
                                                      }];

self.collectionView.dataSource = dataSource;

Sectioned UICollectionViewController

DATASource provides an easy way to show an grouped UICollectionView, you just need to specify the attribute we should use to group your items. This attribute is located in the dataSource initializer as a parameter called sectionName. This will create a collectionView reusable header.

Check the CollectionViewControllerWithSections Demo for an example of this, were we have a grouped UICollectionView using the first letter of a name as a header, just like the Contacts.app!

UICollectionViewDataSource

DATASource takes ownership of your UICollectionViewDataSource providing boilerplate functionality for the most common tasks, but if you need to override any of the UICollectionViewDataSource methods you can use the DATASourceDelegate. Check the CollectionView Demo where we show how to add a footer view to your DATASource backed UICollectionView.

Customizing change animations

By default UITableViewRowAnimation.automatic is used to animate inserts, updates and deletes, but if you want to overwrite this animation types you can use the animations dictionary on DATASource.

Animate insertions using fade

let dataSource = ...
dataSource.animations[.insert] = .fade

Disabling all animations

let dataSource = ...
dataSource.animations = [.update: .none, .move  : .none, .insert: .none]

Installation

DATASource is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'DATASource', '~> 7'

DATASource is also available through Carthage. To install it, simply add the following line to your Cartfile:

github "SyncDB/DATASource" ~> 7.0

Author

Elvis Nuñez, @3lvis

License

DATASource is available under the MIT license. See the LICENSE file for more info.

Footnotes:

1.- Quoted from the RealmResultsController article.

datasource's People

Contributors

3lvis avatar altyus avatar askeland avatar attila-bardos avatar batjo avatar gitter-badger avatar nselvis avatar rlester avatar screenworker avatar tibibo avatar tommypeps avatar yonat avatar zarv1k avatar zenangst avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

datasource's Issues

NSSortDescriptor and sectionName

When using sortDescriptors with sectionName, the sectioName descriptor has to be in the top, this is a stupid bug by NSFetchedResultsController.

Wrong:

let request: NSFetchRequest = NSFetchRequest(entityName: "User")
request.sortDescriptors = [
    NSSortDescriptor(key: "count", ascending: true),
    NSSortDescriptor(key: "name", ascending: true),
    NSSortDescriptor(key: "firstLetterOfName", ascending: true)
]

let dataSource = DATASource(tableView: self.tableView, cellIdentifier: CustomCell.Identifier, fetchRequest: request, mainContext: self.dataStack!.mainContext, sectionName: "firstLetterOfName") { cell, item, indexPath in
}

Correct:

let request: NSFetchRequest = NSFetchRequest(entityName: "User")
request.sortDescriptors = [
    NSSortDescriptor(key: "firstLetterOfName", ascending: true),
    NSSortDescriptor(key: "count", ascending: true),
    NSSortDescriptor(key: "name", ascending: true)
]

let dataSource = DATASource(tableView: self.tableView, cellIdentifier: CustomCell.Identifier, fetchRequest: request, mainContext: self.dataStack!.mainContext, sectionName: "firstLetterOfName") { cell, item, indexPath in
}

Custom UITableViewCell

Potentionaly really stupid question. Does this work with custom UITableViewCell? If so, can you please give me any hint. I cannot get it working. Thanks!

Assertion failure in -[UITableView _endCellAnimationsWithContext

Firstly, thank you so much for this library! I've been messing with NSFetchedResultsController + Sections for days now and this just solved all my problems - except one... For some reason I can't get a custom UITableViewCell cell subclass (in Storyboards) to work with this library.

Any help would be much appreciated.
Thanks in advance!

Cannot get editActionsForRowAtIndexPath: to work

Hi! No matter what I do I cannot get this to work.

    override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
        let block = UITableViewRowAction(style: .Normal, title: "Block") { action, index in
            print("Block")
        }
        let delete = UITableViewRowAction(style: .Default, title: "Delete") { action, index in
            print("Delete")
        }
        return [delete, block]
    }

    func dataSource(dataSource: DATASource, tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        return true
    }

    func dataSource(dataSource: DATASource, tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    }

IMHO you are missing something like this

func dataSource(dataSource: DATASource, tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]?

In case not, please correct me.

Thank you!

How to change predicate on fetchrequest?

Hey 3lvis,

i need to change the predicate when text change called on e.g. SearchBar. But there is no way to access the fetchedResultController to update the predicates!

What i need is something like this:

let frc = myDataSource.fetchedResultsController
frc.fetchRequest.predicate = NSPredicate(format: "firstname CONTAINS[cd] %@", searchString)
try! frc.performFetch()
        
tableView.reloadData()

Make it easier to display a list of indexed items

Implementing

- (NSArray *)sectionIndexTitlesForDataSource:(UITableView *)tableView;

- (NSInteger)dataSource:(UITableView *)tableView
sectionForSectionIndexTitle:(NSString *)title
                atIndex:(NSInteger)index;

should be way easier.

Cells placed into wrong section

Hi, I have rather big problem, when I use DATASource to place fetched objects from Core Data to UITableView with sections, some of the objects will get placed to wrong section.

I am using following code:

    lazy var dataSource: DATASource = {
        let request: NSFetchRequest = NSFetchRequest(entityName: "TypicalFindingDescription")
        request.sortDescriptors = [NSSortDescriptor(key: "materialRemoteID", ascending: true)]

        let dataSource = DATASource(tableView: self.tableView, cellIdentifier: TypicalDescriptionTableViewCell.Identifier, fetchRequest: request, mainContext: self.dataStack.mainContext, sectionName: "materialName", configuration: {
            cell, item, indexPath in
            if let name = item.valueForKey("name") as? String, let materialName = item.valueForKey("materialName") as? String, let materialRemoteID = item.valueForKey("materialRemoteID") as? Int {
                if let cell = cell as? TypicalDescriptionTableViewCell {
                    cell.textLabel!.text = name
                    cell.textLabel!.lineBreakMode = .ByWordWrapping
                    cell.textLabel!.numberOfLines = 0
                }
            }
        })

        return dataSource
    }()

I triple checked that the data are correctly stored in Core Data.

This actually occurs on two different Entities, according to my testers, but I haven't checked the other one.

Thank you for any help.

Two DATASource instances with the same cellIdentifier but should be different

My Model

capture d ecran 2015-11-04 a 15 06 45

MyViewController

@property (nonatomic) DATAStack *dataStack;
@property (nonatomic) DATASource *dataSource;
@property (nonatomic) DATASource *dataSourceCollection;
.
.
.
- (DATAStack *)dataStack
{
    if (_dataStack) return _dataStack;

    _dataStack = [[DATAStack alloc] initWithModelName:@"Model"];

    return _dataStack;
}
- (DATASource *)dataSource
{
    if (_dataSource) return _dataSource;
    _dataStack = [self dataStack];

    NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Program"];
    request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"remoteID"
                                                              ascending:YES]];

    request.predicate = [NSPredicate predicateWithFormat:@"f2fEvent.remoteID == %@", self.event.remoteID];
    _dataSource = [[DATASource alloc] initWithTableView:self.tableView
                                           fetchRequest:request     
                                         cellIdentifier:@"SyncProgramCell"
                                            mainContext:self.dataStack.mainContext
                                          configuration:^(UITableViewCell *cell,
                                                          Program *item,
                                                          NSIndexPath *indexPath)
                   {

                      //Implementing Cell
                   }];

    return _dataSource;
}

-(DATASource*)dataSourceCollection
{
    if(_dataSourceCollection) return _dataSourceCollection;
    if (!_dataStack) {
        _dataStack = [self dataStack];
    }
    NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Place"];
    request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"profile"
                                                              ascending:YES]];

    request.predicate = [NSPredicate predicateWithFormat:@"f2fEvent.remoteID == %@", self.event.remoteID];


    _dataSourceCollection = [[DATASource alloc] initWithCollectionView:self.collectionView
                                                          fetchRequest:request
                                                        cellIdentifier:@"SyncProfileCount"
                                                           mainContext:self.dataStack.mainContext
                                                         configuration:^(id cell, Place *item, NSIndexPath *indexPath)
    {

             // Implemantation Cell

    }];

    return _dataSource;


}

-(void)registerTableViewCell
{
    UINib *nib = [UINib nibWithNibName:@"ViewF2FDetail"
                                bundle:[NSBundle mainBundle]];
    UINib *nibCollection = [UINib nibWithNibName:@"SyncPlaceCell"
                                bundle:[NSBundle mainBundle]];

    //Add TableViewCell Config
    [self.tableView registerNib:nib
         forCellReuseIdentifier:@"SyncProgramCell"];

    //Add CollectionViewCell Config
    [self.collectionView registerNib:nibCollection
          forCellWithReuseIdentifier:@"SyncProfileCount"];
//    [self.collectionView registerClass:[JRProfileCollectionViewCell class]
//            forCellWithReuseIdentifier:@"SyncProfileCount"];

}

-(void)viewDidLoad
{
    [super viewDidLoad];
    [self registerTableViewCell];

    [self.tableView setDataSource:self.dataSource];
    [self.tableView setDelegate:self];

    [self.collectionView setDataSource:self.dataSourceCollection];
 .
 .
 .
}

I do understand as this ins possible

capture d ecran 2015-11-04 a 15 15 19

I see #25 but this error is not

DATASource does not call tableview delegate methods while using with Objective-C umbrela

I'm trying DATASource in a project and it doesn't seem to work.

I setup the DATASource object accordingly:

    NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Session"];
    request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES]];
    NSManagedObjectContext *context = [[CodecampDataStack sharedStack].dataStack mainContext];

    DATASource *dataSource = [[DATASource alloc] initWithTableView:self.tableView
                                                    cellIdentifier:kSessionTableViewCellReusableIdentifier
                                                      fetchRequest:request
                                                       mainContext:context
                                                       sectionName:nil
                                                     configuration:^(UITableViewCell * _Nonnull cell, NSManagedObject * _Nonnull item, NSIndexPath * _Nonnull indexPath) {

                                                         cell.textLabel.text = [item valueForKey:@"name"];
                                                     }];
    self.tableView.dataSource = dataSource;

But it seems that the tableView delegate methods (inside DATASource) are not called.
calling po dataSource.objectsCount returns, as expected, 67.

Project can be found here: https://github.com/cyupa/Codecamp-iOS
UITableViewClass: SessionsTableViewController.

Crash _endItemAnimationsWithInvalidationContext:tentativelyForReordering:

screen shot 2016-04-25 at 09 18 58

2016-04-25 09:11:29.978 iOS Development[2277:52401] *** Assertion failure in -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.60.7/UICollectionView.m:4422

2016-04-25 09:19:24.460 iOS Development[2277:52401] CoreData: error: Serious application error.  An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:.  attempt to delete item 24 from section 0 which only contains 22 items before the update with userInfo (null)

EXC_BAD_ACCESS on tableView.endUpdates()

Hi, I have been using DATASource for a hile now with Sync, in my project everything works fine in iOS 9, but testing in iOS 8.4 throws an EXC_BAD_ACCESS on public func controllerDidChangeContent specifically on tableView.endUpdates() . Could you guide me in what can be wrong? Thanks

Support missing methods for UICollectionViewDataSource

// The view that is returned must be retrieved from a call to -dequeueReusableSupplementaryViewOfKind:withReuseIdentifier:forIndexPath:
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath;

Handling message when tableview is empty

I think that it would be useful to expose some delegate to enable setting custom messages when table view is empty (sorry if this is already possible, but I could not find how). Currently I am using something like this: http://stackoverflow.com/questions/28532926/if-no-table-view-results-display-no-results-on-screen

To get it working here ,while using this pod, I added a new delegate (you can check here: https://github.com/guilhermekrz/DATASource/commit/c94e89dcfe291b105fdc07d408bf1b60a40850de).

However I don't think that this is the best way to expose this. Any ideas?

Number of sections returns one, even if theres is no objects

I want show custom message when table view is empty, but it always return 1, even if theres is no data.

public func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        print(self.fetchedResultsController.sections?.count)
        return self.fetchedResultsController.sections?.count ?? 0
    }

But, when i use this function without implementing DATASource, just in my own table, it returns correct count of sections:

public func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        print(self.fetchedResultsController.sections?.count)
        return self.fetchedResultsController.sections?.count ?? 0
    }

Can't find any explanation for that.

Support multiple cells

Not super critical, but would be great if DATASource could support more than one cell.

Like if you had a list of members and the owner of the group gets presented using a different cell.

Initializers shown in readme don't actually exist

The readme shows the following two methods as examples, but the library actually includes a mainContext param in the two DATASource initializers.

DATASource *dataSource = [[DATASource alloc] initWithTableView:self.tableView
                                                  fetchRequest:fetchRequest
                                                cellIdentifier:ANDYCellIdentifier
                                                 configuration:^(UITableViewCell *cell, Task *task, NSIndexPath *indexPath) {
                                                cell.textLabel.text = task.title;
                                            };
DATASource *dataSource = [[DATASource alloc] initWithCollectionView:self.collectionView
                                                       fetchRequest:fetchRequest
                                                     cellIdentifier:ANDYCellIdentifier
                                                      configuration:^(UICollectionView *cell, Task *task, NSIndexPath *indexPath) {
                                                cell.textLabel.text = task.title;
                                            };

The actual methods are:

- (instancetype)initWithTableView:(UITableView *)tableView
                     fetchRequest:(NSFetchRequest *)fetchRequest
                   cellIdentifier:(NSString *)cellIdentifier
                      mainContext:(NSManagedObjectContext *)mainContext
                    configuration:(void (^)(id cell,
                                            id item,
                                            NSIndexPath *indexPath))configuration;
- (instancetype)initWithCollectionView:(UICollectionView *)collectionView
                          fetchRequest:(NSFetchRequest *)fetchRequest
                        cellIdentifier:(NSString *)cellIdentifier
                           mainContext:(NSManagedObjectContext *)mainContext
                         configuration:(void (^)(id cell,
                                                 id item,
                                                 NSIndexPath *indexPath))configuration;

Filtering DATASource

Is it possible to filter DataSource using UISearchBar?
I'm trying but without success. Any help will be appreciated.
Thanks.

Predicate update for DATASource cause crash

In case the new predicate change amount of items, collection view crashed:

2017-05-12 11:23:26.192 SwiftDemo[12755:330575] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (14) must be equal to the number of items contained in that section before the update (16), plus or minus the number of items inserted or deleted from that section (10 inserted, 10 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).'

To repeat this issue just add to Swift Demo project inside one of CollectionViewController:

func saveAction() {
        Helper.addNewUser(dataStack: self.dataStack)
        self.dataSource.predicate = NSPredicate(format: "role == %@", "manager")
 }

Possible solution (rollback "Safer UICollection reloading") in Merge Request — #103

error implementation

  • (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

don't work

    if ([self.delegate respondsToSelector:@selector(dataSource:canEditRowAtIndexPath:)]) {
        [self.delegate dataSource:tableView
            canEditRowAtIndexPath:indexPath];

    }

Multiple dataSource and one tableView. SearchController

I have UIViewController with one UITableView and 3 lazy instances of dataSource and one optional that indicates activeDataSource for my tableView. Each dataSource has own predicate, sortDescriptor. I also added UISegmentedControl with 3 segments for each data source and function that will change activeDataSource and reload data. Every time viewDidLoad() i have function, that fetches data from server and sync it with Core Data and it can take 3-4 seconds. This 3-4 seconds i try randomly tap segmentedControl to change my dataSource and i get error:

Assertion failure in -[UITableView _endCellAnimationsWithContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3512.60.7/UITableView.m:1502
2016-05-19 09:43:19.702 MyApp[9301:2958707] CoreData: error: Serious application error.  An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:.  attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update with userInfo (null)

Yes, i can disable UserInteraction on segmentedControl, but sometimes user doesn't like wait for sync completion and just filter data, that he/she wants.
In addition i want implement searchController, that will need 4th dataSource, and it will filter data more faster.

Any idea, how avoid this error?

No Example to delete items in table-view

Hey 3lvis,

can you please share an example to delete and refresh cells in table-view like:

extension MyViewController:DATASourceDelegate {
    func dataSource(_ dataSource: DATASource, tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: IndexPath) {
        
        tableView.beginUpdates()
        
        if editingStyle == .delete {
            tableView.deleteRows(at: [indexPath], with: .automatic)
        }
        
        tableView.endUpdates()
    }
    
    func dataSource(_ dataSource: DATASource, tableView: UITableView, canEditRowAtIndexPath indexPath: IndexPath) -> Bool {
        return true
    }
 
}

Thank you.

Regards
Peter

Pagination

Is it possible to implement lazy loading rows with DATASource because?

Thanks.

Sectioned UITableView Without Indexes

Hi, according to README by doing this:

func sectionIndexTitlesForDataSource(dataSource: DATASource, tableView: UITableView) -> [String] {
    return [String]()
}

You can get rid of those indexes, that is correct and it works great but, in my app this causes memory leak.

Can you please check your app using this? It might me my mistake, but right now I am not sure at all.

Thanks

are you aware of any Realm equivalent to DATASource?

Sorry if the wrong forum, as this isn't a problem.

I've used DATASource in another project and loved it. On a new project, I'm using Realm as the persistent layer. I've seen some things on the Realm side that do things to replicate NSFetchedResultsController. However, I haven't seen anything yet that does as nice a job as DATASource on the Realm side of things. It could be that I'm just not looking in the right place. But if you knew of a Realm equivalent of DATASource, I'd be happy to hear about it.

Ability to disable section index

Hi!
Due the fact that I could not override func sectionIndexTitlesForTableView(tableView: UITableView) -> [String]? I forked your repo and create a argument in constructor ti disable section index, because I really dont need one in my app, I twisted it only for Swift UITableView as you can see here: https://github.com/AJTY/DATASource/commit/8fe934ebd44d82712c61ee26ecfa12cd5e4bcdbf

In case this is something you would like to have in your project, you can either think of better way how to do that, or I can get it done for all other usage of DATASource and then I can create pull request.

Let me know, if you want me to help you with this or if you are even interested in it. In case I was doing something wrong and I did not needed to do that to achieve what I wanted, throw on me all the dirt you have.

Thanks Syky.

Add support for missing methods in UITableViewDataSource

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;    // fixed font style. use custom view (UILabel) if you want something different
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;

// Moving/reordering

// Allows the reorder accessory view to optionally be shown for a particular row. By default, the reorder control will be shown only if the datasource implements -tableView:moveRowAtIndexPath:toIndexPath:
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath;

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView;                                                    // return list of section titles to display in section index view (e.g. "ABCD...Z#")
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index;  // tell table which section corresponds to section title/index (e.g. "B",1))

// Data manipulation - reorder / moving support

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath;

Helper methods to access fetchedResultsController methods

  • self.dataSource.predicate
    => self.dataSource.fetchedResultsController.fetchRequest.predicate
  • self.dataSource.objectsCount
    => self.dataSource.fetchedResultsController.fetchedObjects?.count
  • self.dataSource.object(indexPath: NSIndexPath)
    => self.dataSource.fetchedResultsController.objectAtIndexPath(NSIndexPath(forRow: index, inSection: 0)) as? Song
  • self.dataSource.indexPath(object: NSManagedObject)
    => self.dataSource.fetchedResultsController.indexPathForObject(song)
  • self.dataSource.objects
    => self.dataSource.fetchedResultsController.fetchedObjects!
  • self.dataSource.isEmpty? {
    => if self.dataSource.fetchedResultsController.fetchedObjects?.count == 0 {

Support of transient property for sectionName

Transient property for sectionName does not supported for now.
When I use 'firstLetter' (transient property) as sectionName in DATASource initializer I got error:
'Invalid keypath firstLetter passed to setPropertiesToFetch:'
There is an issue in default implementation of UIDataSourceTableView.sectionIndexTitlesForTableView:. I suppose this method should detect is property transient and should not execute request when property is transient. Or maybe this metnod should notify developer somehow that when using transient property he must implement DATASourceDelegate.sectionIndexTitlesForDataSource: in this case.

Sorting by distance

Hi,
I'm loading a list of locations in tableView. I have a model with fields "latitude" and "longitude" and I want to sort this list by distance using my current location. How can I sort dataSource?
Thanks.

Multiple cell identifier support

Some times we want to entirely change the cell and load it from different xib or etc. at specific situations but this cool framework limits cell identifier to just one static reusable cell. I'm very interested to know is there a good reason behind this?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.