sindresorhus / Defaults

💾 Swifty and modern UserDefaults
https://swiftpackageindex.com/sindresorhus/Defaults/documentation/defaults
MIT License
1.97k stars 117 forks source link

Support dynamic default value #121

Closed hank121314 closed 1 year ago

hank121314 commented 1 year ago

Summary

Fixes: #108 .

Defaults now accept default value as a getter.

Approach

Replace default value's type with type typealias DefaultGetter = () -> Value. And change Key.defaultValue to a computed property which getter is DefaultGetter.

Thanks

Sorry for the delay of this PR and thanks for your code review 😄 !

sindresorhus commented 1 year ago

Sorry for the delay of this PR and thanks for your code review 😄 !

No need to be sorry. This is open source. We do this stuff for fun when we can.

hank121314 commented 1 year ago

No need to be sorry. This is open source. We do this stuff for fun when we can.

Got it! Well said! Working on this stuff really makes me fun.

I have applied some changes, thanks for your code review once again!

sindresorhus commented 1 year ago

By the way, we now have API docs: https://swiftpackageindex.com/sindresorhus/defaults/main/documentation/defaults/defaults

hank121314 commented 1 year ago

By the way, we now have API docs: swiftpackageindex.com/sindresorhus/defaults/main/documentation/defaults/defaults

This is awesome! It is much better than showing API in readme.md! Thanks!

sindresorhus commented 1 year ago

✨