Latest 1.1
Homepage https://github.com/zzjzz9266a/ObjectMapperCacheManager
License MIT
Platforms ios 9.0, requires ARC
Dependencies ObjectMapper
Authors

ObjectMapperCacheManager

ObjectMapperCacheManagerObjectMapperCacheManagerObjectMapperCacheManager

Installation

Cocoapods

pod 'ObjectMapperCacheManager'

Usage

When store something to a device, "key" is the only identifier, just like UserDefaults in Foundation.

UserDefaults.standard.setValue(["name": "James", "age": 16], forKey: "User")

But, the difference between UserDefaults and CacheManager is the directory in sandbox:

UserDefaults: Home/Library/Preference/
CacheManager: Home/Library/Caches

1. Store key-value data

The data could be a dict or an array

let dict: [String: Any] = ["name": "James", "age": 16]
CacheManager.setCache(json: dict, for: "Json")

let dictArray = [[String: Any]] = [dict]
CacheManager.setCache(json: dictArray, for: "JsonArray")

2. Get cached key-value data

// must declare the type
if let dict: [String: Any] = CacheManager.cacheJson(for: "Json") as? [String: Any]{  
  print(dict)
}

if let array: [[String: Any]] = CacheManager.cacheJson(for: "JsonArray") as? [String: Any]{  
  print(array)
}

3. Store an object or an array of ObjectMapper

The only requirement is that the object must conform to ObjectMapper’s Mappable protocol.

let user: User = User()
CacheManager.setCache(object: user, for: "Object")

let userList = [user]
CacheManager.setCache(array: userList, for: "ObjectArray")

4. Get cached object of array

if let user: User = CacheManager.cache(for: "Object") {
}

if let array: [User] = CacheManager.cacheArray(for: "ObjectArray") {
}

License

ObjectMapperCacheManager is released under an MIT license. See LICENSE for more information.

Latest podspec

{
    "name": "ObjectMapperCacheManager",
    "version": "1.1",
    "summary": "A Light Tool For Cache Of ObjectMapper.",
    "homepage": "https://github.com/zzjzz9266a/ObjectMapperCacheManager",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "zzjzz9266a": "[email protected]"
    },
    "platforms": {
        "ios": "9.0"
    },
    "source": {
        "git": "https://github.com/zzjzz9266a/ObjectMapperCacheManager.git",
        "tag": "v1.1"
    },
    "source_files": "Sources/*.swift",
    "dependencies": {
        "ObjectMapper": []
    },
    "requires_arc": true,
    "swift_version": "4.0"
}

Pin It on Pinterest

Share This