Latest 0.0.4
Homepage https://github.com/PearTreeLabs/PTLDatasource
License MIT
Platforms ios 6.0, requires ARC
Authors

Build Status

Description

Helpers to lighten your view controllers.

Dependencies

  • UIKit

Optional

  • CoreData

Usage

  • In your Podfile, specify:

    pod 'PTLDatasource'
  • And import the necessary headers:

    #import "UIKit+PTLDatasource.h"
    // or
    #import "UIKit+PTLDatasourceFetching.h"
  • If you are not using CoreData in your project, you can exclude PTLFetchedDatasource, by specifying just the Core components in your Podfile:

    pod 'PTLDatasource/Core'

Basic Array Datasource

#import "UIKit+PTLDatasource.h"

// Prepare your table view
[self.tableView registerClass:cellClass forCellReuseIdentifier:identifier];

// Setup your datasource
PTLArrayDatasource *ds = [[PTLArrayDatasource alloc] initWithArray:@[@"Alice", @"Bob", @"Charlie"]];
ds.tabelViewCellIdentifier = identifier
ds.tabelViewCellConfigBlock = ^{ ... }

// Attach it to a table view
self.tableView.dataSource = ds;

Basic Enum Datasource

#import "UIKit+PTLDatasource.h"

typedef NS_ENUM(NSInteger, MyEnum) {
    MyEnumFoo,
    MyEnumBar,
    MyEnumBaz,
    MyEnumCount
};

...

// Prepare your table view
[self.tableView registerClass:cellClass forCellReuseIdentifier:identifier];

// Setup your datasource
NSIndexSet *indecies = [NSIndexSet initWithIndexesInRange:NSMakeRange(0, MyEnumCount)];
PTLIndexDatasource *ds = [[PTLIndexDatasource alloc] initWithIndecies:indecies];
ds.tabelViewCellIdentifier = identifier
ds.tabelViewCellConfigBlock = ^{ ... }

// Attach it to a table view
self.tableView.dataSource = ds;

Advanced Multiple Datasources

#import "UIKit+PTLDatasourceFetching.h"

// Prepare your table view
[self.tableView registerClass:arrayCellClass forCellReuseIdentifier:arrayIdentifier];
[self.tableView registerClass:indexCellClass forCellReuseIdentifier:indexIdentifier];
[self.tableView registerClass:fetchCellClass forCellReuseIdentifier:fetchIdentifier]

// Setup multiple datasources
PTLArrayDatasource *arrayDS = [[PTLArrayDatasource alloc] initWithArray:@[@"Alice", @"Bob", @"Charlie"]];
arrayDS.tabelViewCellIdentifier = arrayIdentifier
arrayDS.tabelViewCellConfigBlock = ^{ ... }

NSIndexSet *indecies = [NSIndexSet initWithIndexesInRange:NSMakeRange(0, MyEnumCount)];
PTLIndexDatasource *indexDS = [[PTLIndexDatasource alloc] initWithIndecies:indecies];
indexDS.tabelViewCellIdentifier = indexIdentifier
indexDS.tabelViewCellConfigBlock = ^{ ... }

NSFetchedResultsController *frc = ...
PTLFetchedDatasource *fetchDS = [[PTLFetchedDatasource alloc] initWithFetchedResults:frc trackChanges:YES];
fetchDS.tabelViewCellIdentifier = fetchIdentifier
fetchDS.tabelViewCellConfigBlock = ^{ ... }

// Concatenate them
PTLCompositeDatasource *ds = [[PTLCompositeDatasource alloc] initWithDatasources:@[arrayDS, indexDS, fetchDS]];

// Attach to a table view
self.tableView.dataSource = ds;

// Handle datasource changes
[ds addChangeObserver:self];

Known Issues

Roadmap

  • Add unit tests for PTLFetchedDatasource, UITableView extensions, UICollectionView extensions
  • Add extensions for sorting and filtering

License

MIT

Contact

Brian Partridge – @brianpartridge on Twitter and App.Net

Latest podspec

{
    "name": "PTLDatasource",
    "version": "0.0.4",
    "summary": "Helpers to lighten your view controllers.",
    "homepage": "https://github.com/PearTreeLabs/PTLDatasource",
    "license": {
        "type": "MIT",
        "file": "LICENSE.txt"
    },
    "authors": {
        "Brian Partridge": "[email protected]"
    },
    "source": {
        "git": "https://github.com/PearTreeLabs/PTLDatasource.git",
        "tag": "0.0.4"
    },
    "requires_arc": true,
    "platforms": {
        "ios": "6.0"
    },
    "subspecs": [
        {
            "name": "Core",
            "source_files": "PTLDatasource/*.{h,m}",
            "exclude_files": "PTLDatasource/*Fetch*.{h,m}",
            "frameworks": "UIKit"
        },
        {
            "name": "Fetching",
            "dependencies": {
                "PTLDatasource/Core": []
            },
            "source_files": "PTLDatasource/*Fetch*.{h,m}",
            "frameworks": "CoreData"
        }
    ]
}

Pin It on Pinterest

Share This