jdfergason / swift-toml Goto Github PK
View Code? Open in Web Editor NEWSwift package for parsing TOML documents
License: Apache License 2.0
Swift package for parsing TOML documents
License: Apache License 2.0
I'm getting this warning when checking this out via SwiftPM:
.build/checkouts/swift-toml/Sources/Toml/Path.swift:41:16: warning: 'Hashable.hashValue' is deprecated as a protocol requirement; conform type 'Path' to 'Hashable' by implementing 'hash(into:)' instead
public var hashValue: Int {
^
.build/checkouts/swift-toml/Sources/Toml/Tokens.swift:37:9: warning: 'Hashable.hashValue' is deprecated as a protocol requirement; conform type 'Token' to 'Hashable' by implementing 'hash(into:)' instead
var hashValue: Int {
Running swift build
with Swift 3.0.1 Preview 3 emits the following warning:
/Users/emlai/Documents/Code/swift-toml/Sources/Parser.swift:133:25: warning: expression implicitly coerced from 'Any?' to Any
toml.set(value: currToken.value, for: key)
^~~~~~~~~~~~~~~
/Users/emlai/Documents/Code/swift-toml/Sources/Parser.swift:133:35: note: provide a default value to avoid this warning
toml.set(value: currToken.value, for: key)
~~~~~~~~~~^~~~~
?? <#default value#>
/Users/emlai/Documents/Code/swift-toml/Sources/Parser.swift:133:35: note: force-unwrap the value to avoid this warning
toml.set(value: currToken.value, for: key)
~~~~~~~~~~^~~~~
!
/Users/emlai/Documents/Code/swift-toml/Sources/Parser.swift:133:35: note: explicitly cast to Any with 'as Any' to silence this warning
toml.set(value: currToken.value, for: key)
~~~~~~~~~~^~~~~
as Any
This seems to be a bug (tested in v0.3.0). I think both of them should return true.
Here's a commit that adds a test case which catches these: 7cfa946. Feel free to merge.
I'm not sure how to fix this though.
It would be good to add this project to https://cocoapods.org
example toml
foo = []
bar = true
full example
let toml = try! Toml(withString: """
foo = []
bar = true
""")
let array: [String]? = toml.array("foo")
print(array!)
Fatal error: 'try!' expression unexpectedly raised an error: Toml.TomlError.SyntaxError("bar = true")
I have a use case where I would need to loop over all root-level tables to check whether each table contains a certain key. Currently this doesn't seem to be possible.
I was previously using YamlSwift, where this was possible using the dictionary
getter:
for (key, value) in yaml.dictionary! {
if let property = value["property"] {
// use `key` and `property`
}
}
It would be nice to have something similar in swift-toml, for example:
for (tableName, table) in toml.tables {
if let property = try? table.double("property") {
// use `tableName` and `property`
}
}
Currently Toml.value
and variants throw an exception if a key does not exist. In practice this has created code that feels rather messy because simply grabbing a value requires a do { ... } catch { ... }
block, a try!
which is frowned upon, or propogating the error up with try and throws.
It would be more swifty to simply return an optional. If the key path requested does not exist then nil would be returned. Ie, Toml.value
would become
public func value<T>(_ path: String...) -> T?
And using the API would change from:
do {
print(try toml.string("key", "path", "to", "value"))
} catch {
// do something to handle the missing key
}
to:
if let val = toml.string("key", "path", "to", "value") {
print(val)
}
@jdfergason Do you have any plans supporting TOML 0.5.0? According to the docs, it's considered very stable and should be mostly compatible with 1.0 โ so it definitely is worth implementing.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.