 
 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)?

        info.objects = objects;
        return info;
    }
}

    func objectAtIndexPath(indexPath: NSIndexPath) -> T {
        return self.sections[indexPath.section].objects[indexPath.row] as T
    }
    func indexPathAtObject(object: T) -> NSIndexPath? {
        let keys: NSArray = self.arrayIndexPath.allKeys
        let index = keys.indexOfObject(object)
        if index != NSNotFound {
            return self.arrayIndexPath[keys[index] as NSCopying] as NSIndexPath?
        } else {
            return nil
        }
    }
    func addObject(object: T) {
        self.addObjects([object])
    }
    func addObjects(objects: [T]) {
        self.controllerWillChangeConect()
        
        let sortedObjects = objects.sorted(sortTerm)
        self.fetchedObjects = (self.fetchedObjects + sortedObjects).sorted(sortTerm)
        self.sections = self.createSections()
        let indexPaths = sortedObjects.map {o in (o, self.indexPathAtObject(o)) }
        for (object, indexPath) in indexPaths {
            self.didChangeObject(object, atIndexPath: nil, forChangeType: NSFetchedResultsChangeType.Insert, newIndexPath: indexPath!)
        }
        
        self.controllerDidChangeContent()
    }
    func createSections() -> [AKUArrayFetchedResultsSectionInfo] {
        if let keyPath = self.sectionsByName {
