Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack Interface #5

Closed
fjbelchi opened this issue Sep 1, 2014 · 9 comments
Closed

Stack Interface #5

fjbelchi opened this issue Sep 1, 2014 · 9 comments
Assignees
Milestone

Comments

@fjbelchi
Copy link
Contributor

fjbelchi commented Sep 1, 2014

Offer a protocol and implementations to let a consumer implement its own custom stack.

@pepicrft pepicrft added this to the 1.0 milestone Sep 1, 2014
@fjbelchi fjbelchi self-assigned this Sep 1, 2014
@pepicrft
Copy link

pepicrft commented Sep 1, 2014

@fjbelchi , lets talk about the protocol. Some ideas:

// Determines if the saving has to be done after each saving request or when the app goes to the bakground.
enum SavingType {
  case .instantSaving, .globalSaving, 
}

// Instance Variables
var model: NSManagedObjectModel
var storeCoordinator: NSPersistentStoreCoordinator
var savingType: SavingType
var logLevel: SugarRecordLogger

// Instance methods
func save(#asynchronously: Bool, (context: NSManagedObjectContext) -> ()))
func perform(#asynchronously: Bool, (context: NSManagedObjectContext) -> ()))
func description() -> String // Returns information about the stack
func cleanUp()

// Class Variables
static var defaultStack: SugarRecordStack

This should be at first the language SugarRecord should know to communicate with them @fjbelchi . Let's take a look and give some ideas!. Once we have it defined we can split the implementation and work separately.

@fjbelchi
Copy link
Contributor Author

fjbelchi commented Sep 2, 2014

I'm still thinking and playing with playground to have a better a idea how the stack could fit well.

This is my initial idea, but not completed obviously:

protocol CoreDataStack {
    var name: String { get }
    var stackDescription: String { get }
    var model: NSManagedObjectModel { get }
    var persistanceStoreCoordinator: NSPersistentStoreCoordinator { get }
    var persistanceStore : [NSPersistentStore] { get }
    init(stackName:String)
}

I will keep investigating and adding more protocols :)

@pepicrft
Copy link

pepicrft commented Sep 2, 2014

@fjbelchi persistantStore is an Array?

@fjbelchi
Copy link
Contributor Author

fjbelchi commented Sep 2, 2014

I think having persistantStore as an array can be flexible for architecture where it might be need it. In most of the scenario for simple apps you typically use only 1 persitantStore.. let's keep thinking about that, there are more pieces to complete the puzzle

@pepicrft
Copy link

pepicrft commented Sep 2, 2014

Mmm I see but I think this is something internal to the stack that SugarRecord shouldn't know about @fjbelchi . One more thing, what about the communication of SR with the stack?, methods that stacks should implement?

@fjbelchi
Copy link
Contributor Author

fjbelchi commented Sep 3, 2014

Step by step, still testing.. what's your though?

protocol SugarRecordStack : SugarRecordSave {
    var name: String { get }
    var stackDescription: String { get }
    var model: NSManagedObjectModel { get }
    var persistanceStoreCoordinator: NSPersistentStoreCoordinator { get }
    var persistanceStore : [NSPersistentStore] { get }
    init(stackName:String)
}

protocol SugarRecordSave {
    func save() -> (Bool, NSError?)
    func save(completion: (Bool, NSError?) -> ())
}

protocol SugarRecordTable : SugarRecordSave {
    typealias object
    init(stack: SugarRecordStack)
}

@pepicrft
Copy link

pepicrft commented Sep 3, 2014

What's the SugarRecordTable for? @fjbelchi

@fjbelchi
Copy link
Contributor Author

fjbelchi commented Sep 4, 2014

Still thinking how to add the objects, more tweaks:

class SugarRecord {

    let db : SugarRecordStack

    init(stack:SugarRecordStack) {
        self.db = stack;
    }

    // -- Perhaps this should be a factory for the stacks
}

protocol SugarRecordStack : SugarRecordSave {
    var name: String { get }
    var stackDescription: String { get }
    init(stackName:String)
}

protocol CoreDataStack : SugarRecordStack {
    var model: NSManagedObjectModel { get }
    var persistanceStoreCoordinator: NSPersistentStoreCoordinator { get }
    var persistanceStore : [NSPersistentStore] { get }
}

protocol SugarRecordSave {
    func save() -> (Bool, NSError?)
    func save(completion: (Bool, NSError?) -> ())
}

protocol CoreDataSave : SugarRecordSave {
    func save(context:NSManagedObjectContext) -> (Bool, NSError?)
    func save(context:NSManagedObjectContext, completion: (Bool, NSError?) -> ())
}

protocol SugarRecordTable : SugarRecordSave {
    typealias object
    init(stack: SugarRecordStack)
}

// SugarRecord.db.save()

@pepicrft pepicrft assigned pepicrft and unassigned fjbelchi Sep 16, 2014
@pepicrft
Copy link

Working on it here #18

This was referenced Sep 16, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants