Swiftpack.co - Package - JonnyGamer/PappasKit

PappasKit

Welcome to PappasKit! Developed by Jonathan Pappas.

You can add us to your Swift Package Manager like so:

https://github.com/JonnyGamer/PappasKit

Features

The following explains what PappasKit does.


Enums

PappasKit greatly expands the use of enums in Swift.

Advanced Enum Conformances

Instead of only String, Int, and Floating Point Numbers.. PappasKit extends enums to be able to conform to Bool, Range, and ClosedRange.

enum Foo: Bool {
    case foo = true
    case bar = false
}
enum Foo: ClosedRange<Double> {
    case foo = "1...inf"
    case bar = "01...inf"
}
print(Foo.foo.rawValue == 1...(Double.infinity))
print(Foo.foo == Foo.bar) // Surprisingly True

Generic Enum Conformances

PappasKit also allows enums to conform to generic objects like Array, Set, Dictionary, and their Recursive Versions (i.e. [[[Int]]] or [[String]:[Int:Int]])

enum Foo: [Int] {
    case foo = "[5,6,7,7]"
}
print(Foo.foo.rawValue == [5, 6, 7, 7])
enum Foo: [String:[Int]] {
    case foo = "['foo bar': [1, 2, 3, 4], 'hello': [1, 2, 3, 4]]"
}
print(Foo.foo.rawValue == ['foo bar': [1, 2, 3, 4], 'hello': [1, 2, 3, 4]])

Optional Enum Conformances

PappasKit also allows enums to conform to optionals.

enum Hii: Bool? {
    typealias RawValue = Bool?
    case boo = true
    case bot = false
    case too = 0 // This is `nil`
}

Note: if you are conforming an enum to an optional version of itself, it must also conform to the CaseIteralble protocol.

// This syntax is super neat!
enum Hi: Hi?, Enum {
    case boo = "boo"
    case bot = "bot"
    case too = 0 // This is `nil`
}
Hi.boo == Hi.boo.rawValue // true

Enum Todos

These examples do not work just yet.

enum foo: [foo] {}

Github

link
Stars: 0

Dependencies

Used By

Total: 0

Releases

0.1.1 - 2020-10-13 16:12:22

0.1.0 - 2020-10-13 16:10:48

0.0.9 - 2020-10-11 23:31:21

0.0.8 - 2020-10-11 23:29:55

0.0.7 - 2020-10-11 23:27:42

0.0.6 - 2020-10-03 21:23:47

0.0.5 - 2020-10-03 20:52:01

0.0.4 - 2020-10-03 18:03:37

0.0.3 - 2020-10-03 17:55:31

0.0.1 - 2020-10-03 17:50:20

init foo