 
 import Foundation
 import UIKit
+import CoreData
+
+protocol AVOArrayControllerDelegate: NSObjectProtocol, NSFetchedResultsControllerDelegate {
+}
 
 class AVOArrayController<T: NSCopying> {
+    var delegate: AVOArrayControllerDelegate!
     var fetchedObjects: [T]
     let sortTerm: ((T, T) -> Bool)
     let sectionsByName: (T -> NSCopying)?


    func objectAtIndexPath(indexPath: NSIndexPath) -> T {
        return self.sections[indexPath.section].objects[indexPath.row] as T
    }
    func createSections() -> [AKUArrayFetchedResultsSectionInfo] {
        if let keyPath = self.sectionsByName {

        info.objects = objects;
        return info;
    }
    func controllerWillChangeConect() {
        if self.delegate != nil && self.delegate.respondsToSelector(NSSelectorFromString("controllerWillChangeContent:")) {
            self.delegate.controllerWillChangeContent!(self as Any as NSFetchedResultsController)
        }
    }
    func controllerDidChangeContent() {
        if self.delegate != nil && self.delegate.respondsToSelector(NSSelectorFromString("controllerDidChangeContent:")) {
            self.delegate.controllerDidChangeContent!(self as Any as NSFetchedResultsController)
        }
    }
    func didChangeObject(object: T, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath) {
        if self.delegate != nil && self.delegate.respondsToSelector(NSSelectorFromString("controller:didChangeObject:atIndexPath:forChangeType:newIndexPath:")) {
            self.delegate.controller!(self as Any as NSFetchedResultsController, didChangeObject: object, atIndexPath: indexPath, forChangeType: type, newIndexPath: newIndexPath)
        }
    }
}