用于 FAA 飞行员认证数据库的 Swift 解析器

SwiftAirmen:FAA飞行员数据库解析器

SwiftAirmen将
FAA飞行员认证数据库
解析为原生Swift结构,这些结构是严格定义的,没有数据怪异。您必须
从该网站下载CSV格式的飞行员数据库副本才能
与此库一起使用。

要求

此库是为在任何平台或
架构上与 Swift 5.5 或更高版本一起使用而构建的。

安装

使用 Swift Package Manager 将 SwiftAirmen 包含在您的项目中:

let package = Package(
    // [...]
    dependencies: [
        .package(url: "https://github.com/RISCfuture/SwiftAirmen", branch: "master")
    ],
    // [...]
)

请务必将 SwiftAirmen 作为依赖项包含在您的条目中。.target

用法

要解析飞行员记录,请创建一个实例,并为其提供下载的 CSV 记录的
路径:
Parser

import SwiftAirmen

let parser = SwiftAirmen.Parser(directory: yourDirectoryURL)
try parser.parse(callback: { airmen in
    // your code here
}, errorCallback: { error in
    // your error handler here
})

parse异步执行,并在解析
完成后调用回调。block 参数是将飞行员 ID(如
)映射到记录的字典。
airmenA4760216Airman

记录包含有关飞行员及其证书的信息:Airman

let airman = airmen["A4760216"]
print(airman.firstName)
for cert in airman.certificates {
    guard case let .pilot(level, ratings, centerlineThrust) = cert else { continue }
    if level == .airlineTransport {
        // your code continues
    }
}

If you wish to track the progress of the parsing operation,
returns a instance that you can use. Any parsing errors are
non-interruptive and will be given to you in the error callback, which is
invoked once per parse error. The final parameter passed to the
callback includes those records that were parsed without error.
parseProgressairmen

Parsing is an expensive operation. See the class for methods that will
allow you to parse a subset of the airmen certification data.
Parser

GitHub

点击跳转