import LMStorage
struct Movie: LMCodable {
let title: String?
let description: String?
let category: String?
let year: Int?
let rate: String?
let link: String?
let image: String?
}
Parsing the JSON movie using a Data type returned by the request
let movie = Movie(data)
Parsing a local JSON file
let movie: Movie? = Movie.getItem(from: "file_name")
import LMStorage
struct Movie: LMCodable {
let title: String?
let description: String?
let category: String?
let year: Int?
let rate: String?
let link: String?
let image: String?
}
Parsing the JSON movie using a Data type returned by the request
let data: Data = ...
let movies: [Movie] = data.toItems()
Parsing a local JSON file
let movies: [Movie] = Movie.getItems(from: "movies_file_name")
🎓 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 {
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", age: 30)
let storage = UserStorage()
storage.create(user)
/// Saving secure user example
let user = User(id: "2", name: "Test", 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
}
LMStorage
💾 LMStorage is a framework which reduces the complexity of managing a persistent layer.
❗️Requirements
⚒ Installation
Swift Package Manager
LMStorage is available through SPM. To install it, follow the steps:
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:
and run
pod install
🎓 How to use LMCodable
Parsing a dictionary
Parsing the JSON movie using a
Data
type returned by the requestParsing a local JSON file
Parsing an array
Parsing the JSON movie using a
Data
type returned by the requestParsing a local JSON file
🎓 How to use LMDefaults
Import library in your file:
Create a struct for your Defaults files:
Than, in the view controller just save what you need:
🎓 How to use LMStorage
Import library in your file:
If you need more examples, take a look at
Example project
.🙋🏻 Communication
📜 License
LMStorage is under MIT license. See the LICENSE file for more info.