Coder Social home page Coder Social logo

swift-toml's Introduction

Build Status codebeat badge

SwiftToml

SwiftToml is a TOML parser written in the swift language. TOML is an intuitive configuration file format that is designed to be easy for humans to read and computers to parse.

SwiftToml currently parses files that conform to version 0.4.0 of the TOML spec.

For full details of writing TOML files see the TOML documentation.

Quickstart

TOML files are parsed using one of two functions:

  1. Read TOML from file
  2. Parse TOML from string

Both functions return a Toml object of parsed key/value pairs

Parse TOML from file on disk

import Toml
let toml = try Toml(contentsOfFile: "/path/to/file.toml")

Parse TOML from string

import Toml
let toml = try Toml(withString: "answer = 42")

Get raw values from TOML document

import Toml
let toml = try Toml(contentsOfFile: "/path/to/file.toml")

// string value
print(toml.string("table1", "name"))

// boolean value
print(toml.bool("table1", "manager"))

// integer value
print(toml.int("table1", "age"))

// double value
print(toml.double("table1", "rating"))

// date value
print(toml.date("table1", "birthday"))

// get value and resolve type at runtime
print(try toml.value("title")!)

// get array of type [String]
let array: [String] = toml.array("locations")!

// get table
let table1 = toml.table("table1")

// iterate over all tables at the root level
for (tablePath, table) in toml.tables() { ... }

// iterate over all tables under table1
for (tablePath, table) in toml.tables("table1") { ... }

Installation

Add the project to to your Package.swift file as a dependency:

dependencies: [
    .Package(url: "http://github.com/jdfergason/swift-toml", majorVersion: 1)
]

Compatibility

SwiftToml is compatible with Swift 4.0.3 and TOML 0.4.0.

It has been tested with Swift 4.0.3 on Mac OS X and Ubuntu 16.04.

Tests

To run the unit tests checkout the repository and type:

swift test

License

Apache License 2.0

swift-toml's People

Contributors

emlai avatar jdfergason avatar jeehut avatar kandelvijaya avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.