Latest 4.1.2
Homepage https://github.com/tadija/AECoreDataUI
License MIT
Platforms ios 8.0
Authors

Swift 4.2
Platforms iOS
CocoaPods
Carthage
Swift Package Manager
License MIT

Super awesome Core Data driven UI for iOS written in Swift

I made this for personal use, but feel free to use it or contribute.
For more examples check out Sources and Tests.

Index

Intro

AECoreDataUI was previously part of AERecord,
so you may want to check that also.

When it comes to connecting data with the UI, nice approach is to use NSFetchedResultsController.
CoreDataTableViewController wrapper from Stanford’s CS193p is so great at it, that I’ve written it in Swift and made CoreDataCollectionViewController too in the same fashion.

Features

  • Core Data driven UITableViewController (UI automatically reflects data in Core Data model)
  • Core Data driven UICollectionViewController (UI automatically reflects data in Core Data model)

Usage

You may check this demo project for example.

CoreDataTableViewController

CoreDataTableViewController mostly just copies the code from NSFetchedResultsController
documentation page into a subclass of UITableViewController.

Just subclass it and set it’s fetchedResultsController property.

After that you’ll only have to implement tableView(_:cellForRowAtIndexPath:)
and fetchedResultsController will take care of other required data source methods.
It will also update UITableView whenever the underlying data changes (insert, delete, update, move).

Example

import UIKit
import CoreData

class MyTableViewController: CoreDataTableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
        refreshData()
    }

    func refreshData() {
        let sortDescriptors = [NSSortDescriptor(key: "timeStamp", ascending: true)]
        let request = Event.createFetchRequest(sortDescriptors: sortDescriptors)
        fetchedResultsController = NSFetchedResultsController(fetchRequest: request,
                                                              managedObjectContext: AERecord.Context.default,
                                                              sectionNameKeyPath: nil, cacheName: nil)
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as UITableViewCell
        if let frc = fetchedResultsController {
            if let object = frc.objectAtIndexPath(indexPath) as? Event {
                cell.textLabel.text = object.timeStamp.description
            }
        }
        return cell
    }

}

CoreDataCollectionViewController

Same as with the CoreDataTableViewController, just with CoreDataCollectionViewController.

Installation

License

AECoreDataUI is released under the MIT license. See LICENSE for details.

Latest podspec

{
    "name": "AECoreDataUI",
    "version": "4.1.2",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "summary": "Super awesome Core Data driven UI for iOS written in Swift",
    "source": {
        "git": "https://github.com/tadija/AECoreDataUI.git",
        "tag": "4.1.2"
    },
    "source_files": "Sources/AECoreDataUI/*.swift",
    "swift_version": "4.2",
    "platforms": {
        "ios": "8.0"
    },
    "homepage": "https://github.com/tadija/AECoreDataUI",
    "authors": {
        "tadija": "[email protected]"
    },
    "social_media_url": "http://twitter.com/tadija"
}

Pin It on Pinterest

Share This