Swiftpack.co - drekka/UsefulThings as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by drekka.
drekka/UsefulThings 0.0.2
Usefully utilities and classes.
⭐️ 0
🕓 2 years ago
iOS macOS tvOS
.package(url: "https://github.com/drekka/UsefulThings.git", from: "0.0.2")

UsefulThings

A library of useful bits and pieces.

UserDefaults observing

UserDefaultsObserver is a class you can use to watch a parricular user default for changes. For example if you have a user defaults server.url = (String) "http://abc.com, then you could use this to monitor it for changes:

class MyClass {

    private var observer: UserDefaultsObserver<URL>!

    init() {
        observer = UserDefaultsObserver(key: "server.url") { [weak self]  _, newUrl in
            if let url = newUrl {
                self?.doSomething(with: url)
            }
        }
    }

    func doSomething(with _: URL) {
        // Do something with the new url.
    }
}

cast(...)

func cast<T>(_ value: Any?) -> T? is a useful little function for casting from one type to a target type. At the moment it's main feature is the ability to cast from a String to a URL by using URL(string:).

GitHub

link
Stars: 0
Last commit: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

A little tweakiness
2 years ago

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