In this project i wanna build an useful storage with UserDefault which is super easy to deal with and on top of that you can save Codable
Objects
It's pretty simple, just follow these instructions and you have it,
First of all you need a Codable
class/struct like below:
struct User: Codable {
var username: String
var password: String
}
This will add a new object to "user-table"
let user = User(username: "Walter", password: "123456")
HandyStorage.shared.save(object: user, key: "user-table")
Get all users from "user-table"
let users: [User] = HandyStorage.shared.load(key: "user-table")
Update a specific object with new one
let oldUser: User = HandyStorage.shared.load(key: "user-table").first
let newUser = HSUser(username: "Harvey", password: "654321")
HandyStorage.shared.update(oldObject: oldUser, newObject: newUser, key: "user-table")
let user0 = User(username: "Jessica", password: "123456")
let user1 = User(username: "Harvey", password: "654321")
let user2 = User(username: "Mike", password: "321456")
HandyStorage.shared.saveArray(arrayObject: [user0, user1, user2], key: "user-table")
let user: User = HandyStorage.shared.load(key: "user-table").first
HandyStorage.shared.delete(object: user, key: "user-table")
This will delete whole "user-table"
HandyStorage.shared.delete(table: "user-table")
HandyStorage is available through CocoaPods. To install the latest version, simply add the following line to your Podfile:
pod 'HandyStorage'
And then on your terminal run 👇🏻:
pod install
- File > Swift Packages > Add Package Dependency
- Add
https://github.com/shndrs/HandyStorage.git
- Select "Up to Next Major" with "1.0.2"
[email protected], [email protected], shndrs
HandyStorage is available under the MIT license. See the LICENSE file for more info.