Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/RockfordWei/Perfect-INI
Swift encoder and decoder for INI files.
https://github.com/RockfordWei/Perfect-INI
codable ini ini-parser swift
Last synced: 3 months ago
JSON representation
Swift encoder and decoder for INI files.
- Host: GitHub
- URL: https://github.com/RockfordWei/Perfect-INI
- Owner: RockfordWei
- Created: 2018-01-15T21:02:51.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-02-10T04:02:31.000Z (almost 7 years ago)
- Last Synced: 2024-07-12T16:56:11.360Z (4 months ago)
- Topics: codable, ini, ini-parser, swift
- Language: Swift
- Size: 27.3 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Perfect INI Codable
This project provides an encoder / decorder for [INI](https://en.wikipedia.org/wiki/INI_file) files.
This package builds with Swift Package Manager of Swift 4 Tool Chain and is part of the [Perfect](https://github.com/PerfectlySoft/Perfect) project but can be used as an independent module.
## Quick Start
This library provides a pair of `INIEncoder` and `INIDecoder` for INI files.
### Encodable to INI
``` swift
import PerfectINI
struct Person: Codable {
public var name = ""
public var age = 0
}struct Place: Codable {
public var location = ""
public var history = 0
}struct Configuration: Codable {
public var id = 0
public var tag = ""
public var person = Person()
public var place = Place()
}let rocky = Person(name: "rocky", age: 21)
let hongkong = Place(location: "china", history: 1000)let conf = Configuration(id: 101, tag: "my notes", person: rocky, place: hongkong)
let encoder = INIEncoder()
let data = try encoder.encode(conf)
```
The outcome of encoder is a standard Swift `Data` object, and the content should be like this:``` ini
id = 101
tag = my notes[person]
name = rocky
age = 21[place]
history = 1000
location = china
```### INI to Decodable
Assuming `Configuration` and `data` are ready:
``` swift
let decoder = INIDecoder()
let config = try decoder.decode(Configuration.self, from: data)
// configuration loaded.
```## Further Information
For more information on the Perfect project, please visit [perfect.org](http://perfect.org).## Now WeChat Subscription is Available 🇨🇳