-
-
Save laevandus/ceaa861aff9a7916726b50f165af8ea1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct FastfileDocument: FileDocument { | |
let fastfileContents: String | |
init(contents: String) { | |
self.fastfileContents = contents | |
} | |
init(configuration: ReadConfiguration) throws { | |
// TODO: validate the file name | |
guard let data = configuration.file.regularFileContents else { throw CocoaError(.fileReadCorruptFile) } | |
guard let string = String(data: data, encoding: .utf8) else { throw CocoaError(.fileReadCorruptFile) } | |
fastfileContents = string | |
} | |
static var readableContentTypes: [UTType] { | |
return [UTType("public.data")!] | |
} | |
func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper { | |
let data = fastfileContents.data(using: .utf8)! | |
return FileWrapper(regularFileWithContents: data) | |
} | |
// MARK: Accessing Lanes | |
func lanes() -> [Lane] { | |
return FastfileParser.lanes(in: fastfileContents) | |
} | |
} | |
struct Lane: Equatable, Identifiable { | |
let name: String | |
let documentation: String | |
var id: String { | |
return name | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment