Giter Club home page Giter Club logo

aacoredata's Introduction

Table of Contents

#AACoreData

Swift 4.0 Carthage compatible CocoaPods License MIT Build Status License MIT CocoaPods

##Description

AACoreData is a lightweight data persistence wrapper designed to provide an easier solution for CRUD operations using CoreData, written in Swift. It provides a singleton instance to access CoreData objects anywhere in the code and uses 'value types' to define CoreData entities.

##Demonstration

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

##Requirements

  • iOS 8.0+ / Mac OS X 10.9+ / tvOS 9.0+ / watchOS 2.0+
  • Xcode 8.0+

Installation

AACoreData can be installed using CocoaPods, Carthage, or manually.

##CocoaPods

AACoreData is available through CocoaPods. To install CocoaPods, run:

$ gem install cocoapods

Then create a Podfile with the following contents:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

target '<Your Target Name>' do
pod 'AACoreData', '~> 1.0'
end

Finally, run the following command to install it:

$ pod install

##Carthage

To install Carthage, run (using Homebrew):

$ brew update
$ brew install carthage

Then add the following line to your Cartfile:

github "EngrAhsanAli/AACoreData" 

Then import the library in all files where you use it:

import AACoreData

##Manual Installation

Simply copy Classes/AACoreData.swift to your Xcode project and that's it!

#Getting Started

##Define entities

extension AACoreData {
    static let myEntity = AACoreEntity("ExampleEntity")
}

##Shared Instance

You can access the instance easily by adding this line in specific class or globally anywhere outside the class:

let instance = AACoreData.shared

##Creating your own data model

You have to create your own data model file in your project. By default "AACoreData.xcdatamodeld" is assumed to find in your project bundle like ./YouAppName/AACoreData.xcdatamodeld If you want to create different name of data model, then you have to specify it by using singleton property in AppDelegate.swift

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    AACoreData.shared.dataModel = "ExampleDataModel"
    return true
}

##Create new entity object

let record = instance.getNewObject(entityName: .myEntity) as! ExampleEntity

##Save your changes

instance.saveContext()

##Fetch your records

You can fetch your objects easily. Note that parameters 'predicate' and 'sortDescriptors' are optional

instance.fetchRecords(entityName: #ENTITY#, predicate: #PREDICATE#, sortDescriptors: #SORTDECRIPTORS#, completion: #COMPLETION BLOCK#)

You can easily check the object's existence or fetch the required persist data

instance.fetchRecords(entityName: .myEntity, sortDescriptors: [sorter]) { (results) in
if let result = results {
// MARK:- Record(s) found
// You can fetch using loop
}
else {
// MARK:- No Record found
// You can insert new record to avoid redundancy
}
}

##Delete a object

You can easily delete an object using shared instance.

instance.deleteRecord(record)

Tip: Don't forget to save changes after update persisted data using instance.saveContext()

##Delete all objects

You can easily remove all the records from an entity using shared instance

instance.deleteAllRecords(entity: .Example)

#Contributions & License

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

Pull requests are welcome! The best contributions will consist of substitutions or configurations for classes/methods known to block the main thread during a typical app lifecycle.

I would love to know if you are using AACoreData in your app, send an email to Engr. Ahsan Ali

aacoredata's People

Contributors

engrahsanali avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.