HFCore 0.2.1

HFCore 0.2.1

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Jul 2016
SPMSupports SPM

Maintained by HFCoreUI.



 
Depends on:
HFUtility>= 0
RNCryptor>= 0
SwiftKeychainWrapper>= 0
ReachabilitySwift>= 0
 

HFCore 0.2.1

  • By
  • DragonCherry

Example

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

This project contains simple methods that can reduce common and repetitive codes we always writing in iOS application development. The major features are as follows.

Local Data Management

  • HFLocalStorage provides simple way to save and load object

To save into or load from local dictionary(suppose that you have an object somewhere like below)


let storage = HFLocalStorage(fileName: "test.db", directoryType: .LibraryDirectory)

storage.saveObject(["Any", "Kinds", "Of", "NSCoding", "Objects"], "TEST_KEY") // save

let array = storage.loadObject("TEST_KEY") as? [String] // load

  • extensions of NSKeyedArchiver and NSKeyedUnarchiver provides simple way to archive and unarchive object

To archive object that conforms to protocol NSCoding,


NSKeyedArchiver.archiveObject("path/to/file", object: objectToArchive, key: "OBJECT_KEY")

To unarchive archived NSCoding-conformed object from file,


let unarchivedObject = NSKeyedArchiver.archiveObject("path/to/file", key: "OBJECT_KEY")

Data Handling

  • HFJSON provides simple way to get JSON object from String, and vice versa.

Suppose that you have JSON string from server or somewhere,


let dict = HFJSON.jsonFrom(jsonResponseText)

let jsonString = HFJSON.stringFrom(dict)

  • Dictionary+HF provides simple way to pick an object from complicated dictionary

Suppose that a dictionary with data is given below,


{

    "productList": [{

        "productId": 0,

        "productName": "Product 0",

        "components": [{

            "componentId": 100,

            "componentName": "Component 100",

            "parts": [{

                "partId": 1000,

                "partName": "Part 1000"

            },{

                "partId": 2000,

                "partName": "Part 2000"

            }]

        }

    }
}

To get second part name of first component of first product, just call extension method below.


// where jsonDict is an object type of [String: AnyObject]?

let partName = jsonDict?.objectForKeyPath("productList[0].components[0].parts[1].partName") as? String

NSLog("partName: \(partName)")    // will get "Part 2000"

Cryptors

  • HFCryptor provides simple way to encrypt, decrypt data using AES256
  • HFCryptorRSA provides simple way to encrypt, decrypt data using RSA cryptosystem

Everything will work as you expected.

Requirements

Installation

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

pod "HFCore"

Author

DragonCherry, [email protected]

License

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