From TOML to Swift Codable types.

Overview

TOMLDecoder

Swift 5.3 & 5.3.1
Amazon Linux 2
CentOS 8
macOS 11.15
Ubuntu Bionic
Ubuntu Focal

TOML parser for your Swift Codables.

struct Team: Codable {
    struct Player: Codable {
        let id: String
        let health: Int
        let joinDate: Date
    }

    let players: [Player]
}

let team = try TOMLDecoder().decode(Team.self, from: tomlData)

TOMLDecoder has a relatively simple set of APIs. Learn more in the introduction.

Installation

With SwiftPM

.package(url: "https://github.com/dduan/TOMLDecoder", from: "0.2.1")

License

MIT. See LICENSE.md.

Comments
  • How do subtables work?

    How do subtables work?

           let toml = """
    [players]
      [players.'tom']
      id = '33968bc5c8a95'
      health = 80
      joinDate = 2019-03-10 17:40:00-07:00
      [players.'steve']
      id = '33968bc5c8a95'
      health = 80
      joinDate = 2019-03-10 17:40:00-07:00
    """
    
            struct Team: Codable {
                struct Player: Codable {
                    let id: String
                    let health: Int
                    let joinDate: Date
                }
    
                let players: [Player]
            }
    
            let team = try! TOMLDecoder().decode(Team.self, from: toml)
            print(team)
    
    Fatal error: 'try!' expression unexpectedly raised an error: Swift.DecodingError.valueNotFound(Swift.UnkeyedDecodingContainer, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "players", intValue: nil)], debugDescription: "Cannot get unkeyed decoding container -- found null value instead."
    
    opened by publicarray 2
  • In release builds, literal strings incorrectly include opening `'`

    In release builds, literal strings incorrectly include opening `'`

    A trivial TOML file like this:

    foo = 'bar'
    

    is parsed incorrectly in release builds (but correctly in debug builds). The problem doesn’t occur with basic/double-quoted strings.

    import Foundation
    import TOMLDecoder
    
    let toml = """
    foo = 'bar'
    """
    
    struct Decoded: Codable, Equatable {
        let foo: String
    }
    
    let decoded = try! TOMLDecoder().decode(Decoded.self, from: toml)
    
    switch decoded {
    case Decoded(foo: "bar"):
        print("Correct")
    case Decoded(foo: "'bar"):
        print(#"Observed error: "\#(decoded.foo)""#)
    default:
        print(#"Other error: "\#(decoded.foo)""#)
    }
    
    
    opened by JensAyton 1
  • Throws an error instead of crash when single value container is used

    Throws an error instead of crash when single value container is used

    Context

    When a single value decoding container is used and try to decode and fails, instead of throws an error, crash due to a force unwrap.

    What does this PR do?

    changes all of the force unwraps from decodes methods in SingleValueDecodingContainer and throws an error instead.

    opened by guseducampos 1
  • Support Xcode 11

    Support Xcode 11

    Support Xcode 11. Don't worry, this project can be still built on Xcode 10.2. Current Swift syntax is still 5.0.

    • Open this project with Xcode 11 then generates xcworkspace
    • Add platforms to Package.swift
    • Avoid warning
    opened by giginet 1
  • Float parsing skips frac parsing if 0 is first digit after decimal

    Float parsing skips frac parsing if 0 is first digit after decimal

    Issue

    The function normalFloat(_ input: inout Substring) does not correctly parse floats. After parsing the decimal, it calls decIntTextUTF8(_ utf8: inout Substring.UTF8View) again. This function checks to make sure the first digit is not zero. However, with the fractional component of floats this is allowed.

    The result of this bug is that floats parsed that fit this condition (ex: 12.02, -325.0021) will return without the digits following the first 0, and those remaining digits will be left on input causing a parsing error.

    Suggested solution:

    Create a separate function to be called after the decimal which does not perform this first-digit zero-check.

    opened by Solidsilver 0
Releases(0.2.2)
Owner
Daniel Duan
https://duan.ca
Daniel Duan
Modern interface to UserDefaults + Codable support

Default Modern interface to UserDefaults + Codable support What is Default? Default is a library that extends what UserDefaults can do by providing ex

Nicholas Maccharoli 475 Dec 20, 2022
Why not use UserDefaults to store Codable objects 😉

tl;dr You love Swift's Codable protocol and use it everywhere, who doesn't! Here is an easy and very light way to store and retrieve -reasonable amoun

Omar Albeik 452 Oct 17, 2022
CodableFiles - Save and load Codable objects from DocumentDirectory on iOS Devices.

Welcome to CodableFiles, a simple library that provides an easier way to save, load or delete Codable objects in Documents directory. It’s primarily a

Egzon Pllana 36 Dec 20, 2022
AppCodableStorage - Extends `@AppStorage` in SwiftUI to support any Codable object

AppCodableStorage Extends @AppStorage in SwiftUI to support any Codable object.

Andrew Pouliot 19 Nov 25, 2022
CodableCloudKit allows you to easily save and retrieve Codable objects to iCloud Database (CloudKit)

CodableCloudKit CodableCloudKit allows you to easily save and retrieve Codable objects to iCloud Database (CloudKit) Features ℹ️ Add CodableCloudKit f

Laurent Grondin 65 Oct 23, 2022
MoreCodable expands the possibilities of `Codable`.

MoreCodable MoreCodable expands the possibilities of "Codable". Installation Carthage github "tattn/MoreCodable" CocoaPods pod 'MoreCodable' Feature D

Tatsuya Tanaka 372 Dec 7, 2022
Unrealm is an extension on RealmCocoa, which enables Swift native types to be saved in Realm.

Unrealm enables you to easily store Swift native Classes, Structs and Enums into Realm . Stop inheriting from Object! Go for Protocol-Oriented program

Artur  Mkrtchyan 518 Dec 13, 2022
A fast, pure swift MongoDB driver based on Swift NIO built for Server Side Swift

A fast, pure swift MongoDB driver based on Swift NIO built for Server Side Swift. It features a great API and a battle-tested core. Supporting both MongoDB in server and embedded environments.

null 646 Dec 10, 2022
SQLite.swift - A type-safe, Swift-language layer over SQLite3.

SQLite.swift provides compile-time confidence in SQL statement syntax and intent.

Stephen Celis 8.7k Jan 3, 2023
🧡 SQLiteOrm-Swift is an ORM library for SQLite3 built with Swift 5

?? Easy to use SQLite ORM library written with Swift

Yevgeniy Zakharov 25 Oct 6, 2022
ObjectBox Swift - persisting your Swift objects superfast and simple

ObjectBox Swift ObjectBox is a superfast, light-weight object persistence framework. This Swift API seamlessly persists objects on-device for iOS and

ObjectBox 380 Dec 19, 2022
Shows the issue with swift using an ObjC class which has a property from a swift package.

SwiftObjCSwiftTest Shows the issue with swift using an ObjC class which has a property from a swift package. The Swift class (created as @objc derived

Scott Little 0 Nov 8, 2021
Ios-App-ication-Swift - A simple iOS application made in Xcode using Swift

?? iPhone Calculator A simple iOS application made in Xcode using Swift. This ap

Kushal Shingote 1 Feb 2, 2022
Save-the-dot-project-swift - Save the dot project with swift

Save the Dot Apple introduced UIViewPropertyAnimator for iOS 10. We can use this

Kushal Shingote 2 Feb 8, 2022
The Swift Package Index is the place to find Swift packages!

The Swift Package Index helps you make better decisions about the dependencies you use in your apps. The Swift Package Index is a search engine for pa

Swift Package Index 389 Dec 22, 2022
A stand-alone Swift wrapper around the mongo-c client library, enabling access to MongoDB servers.

This package is deprecated in favour of the official Mongo Swift Driver. We advise users to switch to that pack

PerfectlySoft Inc. 54 Jul 9, 2022
Elegant library to manage the interactions between view and model in Swift

An assistant to manage the interactions between view and model ModelAssistant is a mediator between the view and model. This framework is tailored to

Seyed Samad Gholamzadeh 28 Jan 29, 2022
CRUD is an object-relational mapping (ORM) system for Swift 4+.

CRUD is an object-relational mapping (ORM) system for Swift 4+. CRUD takes Swift 4 Codable types and maps them to SQL database tables. CRUD can create tables based on Codable types and perform inserts and updates of objects in those tables. CRUD can also perform selects and joins of tables, all in a type-safe manner.

PerfectlySoft Inc. 61 Nov 18, 2022
CoreXLSX is a Excel spreadsheet (XLSX) format parser written in pure Swift

CoreXLSX Excel spreadsheet (XLSX) format parser written in pure Swift CoreXLSX is a library focused on representing the low-level structure of the XML

null 684 Dec 21, 2022