Latest 0.3.1
Homepage https://github.com/DanielMandea/CoreDataHelper
License MIT
Platforms ios 8.0
Authors

CI Status
Version
License
Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Setup Core Data Entries


import Foundation
import CoreData
import CoreDataStackHelper

final class User: NSManagedObject, AddManagedObject, SaveManagedObject, Fetch {

}

// MARK: - UpdateManangedObject

extension User: UpdateManangedObject {

    public func update(with data: Any) {
        // Checkout data
        guard let data = data as? Dictionary<String, Any> else {
            return
        }
        // Update managed object
        name = data["name"] as? String
        uniqueID = data["uniqueID"] as? String
        age = data["age"] as? NSNumber
    }
}

Setup Core Data Stack

To setup core data stack only call this method:


/**
Use this method in order to load the persistent store
- parameter name:          The name of the container
- parameter descriptions:  The descriptions related to NSPersistentStoreDescription
- parameter block:         The block that is called after completing the process
*/
@available(iOS 10.0, *)
public func setup(with name: String = kDefatultContainerName, descriptions:Array<NSPersistentStoreDescription>?, comletion block:@escaping LoadPersistentStoreCompletion)

Example:


// Call setup in your app delegate
Persistence.store.setup(descriptions: nil) { (persistentStoreDescription, error) in
    if let currentError = error {
        print(currentError)
    }
}

Create new NSManagedObject based on some Dictionary

Helper Methods:


/**
This method is called by all managedObjects in order to save single
- parameter data:          The data received for saving
- parameter context:       The context that should handle the fetch
- parameter completion:    The block that is called after the process completed
*/
static func saveSingle(data:Any, context:NSManagedObjectContext, completion:@escaping CompletionBlock)

/**
This method is called by all managedObjects in order to save multiple
- parameter data:          The data received for saving
- parameter context:       The context that should handle the fetch
- parameter completion:    The block that is called after the process completed
*/
static func saveMultiple(data:Array<Any>, context:NSManagedObjectContext, completion:@escaping CompletionBlock)

Example:

// Save some users
User.saveMultiple(data: users, context: savingContext) { (success, error) in
    // Do smth in the completion
}

Fetch NSManagedObjects

Helper methods:

/**
Use this method i order to fetch some context based on some predicate
- parameter predicate: The predicte that is used for fetch
- parameter context:   The context that will handle the fetch
- return: An instance of NSArray containing Self or nil
*/
static func fetch(with predicate: NSPredicate?, in context: NSManagedObjectContext) throws -> Array<Self>?
/**
Use this method i order to count an entity in context based on some predicate
- parameter predicate: The predicte that is used for fetch
- parameter context:   The context that will handle the fetch
- return: An instance of Int or nil
*/
static func count(with predicate: NSPredicate?, in context: NSManagedObjectContext) throws -> Int?

Example:

do {
    if let data = try User.fetch(with: nil, in: self.viewContext) {
        self.allUsers = data
    }
} catch {
    print(error)
}

Requirements

iOS 10

Installation

CoreDataStackHelper is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "CoreDataStackHelper"

Author

DanielMandea, daniel.mandea@ro.ibm.com

License

CoreDataStackHelper is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "CoreDataStackHelper",
    "version": "0.3.1",
    "summary": "Lightweight CoreData helper for creting / saving anf fetching NSManageObjects",
    "description": "This pod in intended to enhance the work with light core data stacks.nYou can find helpers for the following needs:n1. Create single instances from a single NSManagedObject subclass based form some datan2. Create multiple instances from a single NSManagedObject subclass based on an array of datan3. Create and save multiple / single instances fo NSManagedObject subclassn4. Clean and light way of fetching NSManagedObject subclassesnPlease check example project in order to get in touch with what this pod can do.",
    "homepage": "https://github.com/DanielMandea/CoreDataHelper",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "DanielMandea": "daniel.mandea@ro.ibm.com"
    },
    "source": {
        "git": "https://github.com/DanielMandea/CoreDataHelper.git",
        "tag": "0.3.1"
    },
    "social_media_url": "https://twitter.com/MandeaDaniel",
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "CoreDataStackHelper/Classes/**/*",
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This