Swiftpack.co -  thejohnlima/LMStorage as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
thejohnlima/LMStorage
๐Ÿ’พ LMStorage is a framework which reduces the complexity of managing a persistent layer.
.package(url: "https://github.com/thejohnlima/LMStorage.git", from: "1.0.5")

LMStorage


๐Ÿ’พ LMStorage is a framework which reduces the complexity of managing a persistent layer.

โ—๏ธRequirements

  • iOS 12.1+
  • tvOS 9.0+
  • Swift 5.0+

โš’ Installation

Swift Package Manager

LMStorage is available through SPM. To install it, follow the steps:

Open Xcode project > File > Swift Packages > Add Package Dependecy

After that, put the url in the field: https://github.com/thejohnlima/LMStorage.git

CocoaPods

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

pod 'LMStorage'

and run pod install

๐ŸŽ“ How to use LMDefaults

Import library in your file:

import LMStorage

Create a struct for your Defaults files:

struct MyDefaults: LMDefaults {
  enum Keys: String {
    case currentUser
    case accessToken
    case haveSeenOnboarding
  }
}

Than, in the view controller just save what you need:

class ViewController: UIViewController {

  let viewModel = ViewModel()

  override func viewDidLoad() {
    super.viewDidLoad()

    MyDefaults.set(true, forKey: .haveSeenOnboarding)

    let haveSeenOnboarding = MyDefaults.bool(forKey: .haveSeenOnboarding)

    print("Have Seen Onboarding: \(haveSeenOnboarding)")
  }
}

๐ŸŽ“ How to use LMStorage

Import library in your file:

import LMStorage
/// Saving user example
let user = User(id: "1", name: "John John", age: 30)
let storage = UserStorage()
storage.create(user)
/// Saving secure user example
let user = User(id: "2", name: "John John", age: 1130)
let secureStorage = UserSecureStorage()
secureStorage.create(user)
/// Storage Keys Example
struct Key {
  static let container = "LMStorage"
  static let user = "User"
}
/// User Example
struct User: LMCodable {
  let id: String
  let name: String
  let age: Int
}
/// User storage example
struct UserStorage: LMStorageProtocol {
  typealias T = User

  private let storage: LMAbstractStorage<T>

  init() {
    storage = LMStorage(with: Key.user)
  }

  func getFirst() -> User? {
    return storage.getFirst()
  }

  func create(_ register: User) -> Bool {
    return storage.create(register)
  }

  func update(_ register: User) -> Bool {
    return storage.update(register)
  }

  func delete() -> Bool {
    return storage.delete()
  }
}
/// User secure storage example
struct UserSecureStorage: LMStorageProtocol {
  typealias T = User

  private let storage = LMSecureStorage<T>(with: Key.container)

  init() {}

  func getFirst() -> User? {
    return storage.getFirst(key: Key.user)
  }

  func create(_ register: User) -> Bool {
    return storage.create(register, key: Key.user)
  }

  func update(_ register: User) -> Bool {
    return storage.update(register, key: Key.user)
  }

  func delete() -> Bool {
    return storage.delete(key: Key.user)
  }
}

If you need more examples, take a look at Example project.

๐Ÿ™‹๐Ÿปโ€ Communication

  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request. ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป

๐Ÿ“œ License

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

GitHub

link
Stars: 4
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jackโ€™d and SCRUFF. We are two of the worldโ€™s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

Version 1.0.5
2 weeks ago
  • Update LMCodable to parse local files data properly;

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API