Giter Site home page Giter Site logo

ankitthakur / coredatapreference Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 7.79 MB

Using core data as UserDefault settings with encryption (EncryptedCoreData)

License: MIT License

Swift 1.36% Ruby 0.12% Objective-C 0.05% C 0.33% HTML 97.84% CSS 0.28% JavaScript 0.02%
swift4 core-data sqlcipher userdefaults ios

coredatapreference's Introduction

CoreDataPreference

Using core data as UserDefault settings with encryption (EncryptedCoreData)

Build Status GitHub license Coverage Status

Dependencies: 'EncryptedCoreData' for securing db. 'SwiftyBeaver' for logging purpose

Installation

In Project pod file, add above 2 dependencies:


  # Pods for CoreDataDefaults
  pod 'EncryptedCoreData', :git => 'https://github.com/project-imas/encrypted-core-data', :commit => 'b97ffaf2f19dad4d1558bc9b0668cc2e09d17347'
  pod 'SwiftyBeaver'
  

Then add CoreDataDefaults.framework as Embedded framework in Main project Embedded framework

Code Coverage

Code Coverage

Test Report

Code Coverage

Code Sample

do {
    try CoreDataPref.set(value: Float(2.0), forKey: "floatValue")
    try CoreDataPref.set(value: 2, forKey: "IntValue")
    try CoreDataPref.set(value: ["key1": "value1", "key2": "value2"], forKey: "dictionary")
    try CoreDataPref.set(value: ["value1", "value2"], forKey: "array")
    try CoreDataPref.set(value: true, forKey: "bool")
        
    let floatValue = try CoreDataPref.float(forKey: "floatValue")
    let intValue = try CoreDataPref.integer(forKey: "IntValue")
    let dictionary = try CoreDataPref.dictionary(forKey: "dictionary")
    let array = try CoreDataPref.array(forKey: "array")
    let boolValue = try CoreDataPref.boolean(forKey: "bool")
    
    // to remove any value
    try CoreDataDefaults.remove(valueForKey: "arrayValue")        

} catch let error {
    print(error)
}

If we want to save any class or struct, just make them Codable, and store it like below

struct Struct1: Codable {
    let value1 = "value1"
    let value2 = "value2"
    let value3 = "value3"
}
struct Struct2: Codable {
    let value1 = "value1"
    let value2 = "value2"
    let struct1Val = Struct1()
}

    do {
        // save struct in preferences
        try CoreDataPref.set(value: Struct2(), forKey: "struct")
        
        // fetch struct from preferences
        let struct = try CoreDataPref.codable(objectType: Struct2.self, forKey: "struct")
        
    } catch let error {
        print(error)
    }

Here is the Swift Lint Report:

$ swiftlint
Loading configuration from '.swiftlint.yml'
Linting Swift files at paths
Linting 'ManagedObectExtension.swift' (1/9)
Linting 'Logger.swift' (2/9)
Linting 'CoreDataManager.swift' (3/9)
Linting 'Obfuscator.swift' (4/9)
Linting 'CoreDataDefaultsCollection.swift' (5/9)
Linting 'CDDefault+CoreDataClass.swift' (6/9)
Linting 'CDDefault+CoreDataProperties.swift' (7/9)
Linting 'CoreDataDefaults.swift' (8/9)
Linting 'CoreDataDefaultsTests.swift' (9/9)
Done linting! Found 0 violations, 0 serious in 9 files.

Contributors To Build the framework and for generating these reports, execute below commands:

#Build the project
xcodebuild clean build -workspace ./CoreDataDefaults.xcworkspace -scheme CoreDataDefaults -sdk iphonesimulator12.1

# Run Test Cases
xcodebuild test -workspace CoreDataDefaults.xcworkspace -scheme CoreDataDefaults  -sdk iphonesimulator12.1 -destination 'platform=iOS Simulator,name=iPhone XR' -resultBundlePath TestResults

# Generating TestResults html report
xchtmlreport -r TestResults

# Generating Code coverage report:
xcov -w CoreDataDefaults.xcworkspace -s CoreDataDefaults -o xcov_output --markdown_report

coredatapreference's People

Contributors

ankitthakur avatar

Watchers

 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.