sunshinejr / SwiftyUserDefaults

Modern Swift API for NSUserDefaults
http://radex.io/swift/nsuserdefaults/static
MIT License
4.86k stars 367 forks source link

KeyPath dynamicMemberLookup support. #199

Closed marty-suzuki closed 5 years ago

marty-suzuki commented 5 years ago

This PR has KeyPath dynamicMemberLookup support in Swift 5.1!

Here is example usage:

extension DefaultsKeyStore {
    var launchCount: DefaultsKey<Int> {
        return .init("launchCount", defaultValue: 0) 
    }
}

func application(_ application: UIApplication, didFinish...) -> Bool {
    Defaults.launchCount += 1
    return true
}

I've add a DefaultsAdapter class to realize above usages because UserDefaults can't support @dynamincMemberLookup annotation. In addition, I've defined conventional SwiftyUserDefaults interfaces to DefaultsType. DefaultsAdapter is adapted DefaultsType, so those work as conventional SwiftyUserDefaults too.

sunshinejr-bot commented 5 years ago
Warnings
:warning: Big PR, try to keep changes smaller if you can
:warning: Any changes to library code should be reflected in the Changelog.

Generated by :no_entry_sign: Danger Swift against 15d7c8dda8f534d82071c76e682e4d773328947c

sunshinejr commented 5 years ago

Hey @marty-suzuki! First of all thanks so much for this PR, you've did an amazing job and you must've spent quite some time to get this one working. I really appreciate that.

I also love the idea that we could use @dynamicMemberLookup - and I didn't know that we can get code completion on that! I played with it a little and it works awesome.

I would need some time to get familiar with it so I can make a good review, but just wanted to let you know that I really like this one!