Swiftpack.co - FelixHerrmann/FHPropertyWrappers as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by FelixHerrmann.
FelixHerrmann/FHPropertyWrappers 1.3.1
Some useful Swift Property Wrappers.
⭐️ 4
🕓 5 weeks ago
iOS macOS tvOS
.package(url: "https://github.com/FelixHerrmann/FHPropertyWrappers.git", from: "1.3.1")

FHPropertyWrappers

Xcode Build SwiftLint

Some useful Swift Property Wrappers.

Requirements

  • macOS 10.10+
  • iOS 9.0+
  • tvOS 9.0+

Installation

Swift Package Manager

Add the following to the dependencies of your Package.swift:

.package(url: "https://github.com/FelixHerrmann/FHPropertyWrappers.git", from: "x.x.x")

Manual

Download the files in the Sources folder and drag them into you project.

Stored

A property wrapper which reads and writes the wrapped value in the UserDefaults store.

It supports all the types that are allowed by UserDefaults. Check all the supported types here.

@Stored("string") var string = ""
@Stored("int") var int: Int
@Stored("array") var array: [String]
@Stored("dictionary") var dictionary [String: Int]

The default value is based on the defaultStoredValue if nothing is set.

In addition to that, Optional, RawRepresentable and Codable are supported too. For non-RawRepresentable enums use Codable.

@Stored("optional") var optional: String?
enum Enumeration: String, Storable {
    case firstCase
    case secondCase
    
    static var defaultStoredValue: Enumeration {
        return .firstCase
    }
}

@Stored("enumeration") var enumeration: Enumeration
struct CustomType: Codable, Storable {
    let name: String
    
    static var defaultStoredValue: CustomType {
        return CustomType(name: "")
    }
}

@Stored("codable") var codable: CustomType

The wrapped value must conform to Storable.

Tip: To store an array of Storable (which is not supported, only RawStorable types are allowed), create a container struct around the array which conforms to Codable.

SecureStored

A property wrapper which reads and writes the wrapped value in the Keychain.

It supports all the base types, most of them rely on Codable. Check all the supported types here.

@SecureStored("string") var string = ""
@SecureStored("int") var int: Int
@SecureStored("array") var array: [String]
@SecureStored("dictionary") var dictionary [String: Int]

The default value is based on the defaultStoredValue if nothing is set.

In addition to that, Optional, RawRepresentable and Codable are supported too. For non-RawRepresentable enums use Codable.

@SecureStored("optional") var optional: String?
enum Enumeration: String, SecureStorable {
    case firstCase
    case secondCase
    
    static var defaultStoredValue: Enumeration {
        return .firstCase
    }
}

@SecureStored("enumeration") var enumeration: Enumeration
struct CustomType: Codable, SecureStorable {
    let name: String
    
    static var defaultStoredValue: CustomType {
        return CustomType(name: "")
    }
}

@SecureStored("codable") var codable: CustomType

The wrapped value must conform to SecureStorable.

License

FHPropertyWrappers is available under the MIT license. See the LICENSE file for more info.

GitHub

link
Stars: 4
Last commit: 5 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

1.3.1
5 weeks ago

What's Changed

New Contributors

Full Changelog: https://github.com/FelixHerrmann/FHPropertyWrappers/compare/1.3.0...1.3.1

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