bannzai / UserDefaultsGenerator

UserDefaultsGenerator generate swift code for easily management for (NS)UserDefaults key and value type.
MIT License
30 stars 1 forks source link

Swift5.1不是可以利用@PropertyWrapper 这个特性做扩展吗? #15

Closed josercc closed 4 years ago

josercc commented 4 years ago

做这个库意义何在? 比如声明

@UserDefault("age",0)
var age:Int

//set
self.age = 18
//get
self.age
bannzai commented 4 years ago

@josercc

UserDefualtsGenerator can be customized for generated swift code with your own stencil template. You can select to use @PropertyWrapper, extension UserDefaults or more testable code with protocol. For example.

public protocol BoolLocalStorage {
  func set(_ value: Bool, forKey key: UDGBoolKey) 
  func get(forKey key: UDGBoolKey) -> Bool
}

extension UserDefaultsGenerator: BoolLocalStorage {
  public  func set(_ value: Bool, forKey key: UDGBoolKey)  { ... }
  public func get(forKey key: UDGBoolKey) -> Bool { ... } 
}

See more detail to README aboutudg generate option. https://github.com/bannzai/UserDefaultsGenerator#udg-generate-command-option-description

And This library user not necessary to write boiler plate swift code. If you want to add or remove UserDefaults functions, you only write yml file and exec udg generate command. So, it is easy and integrate format of UserDefaultsGenerate functions format for your project.

bannzai commented 4 years ago

This issue close.