Skip to content

Instantly share code, notes, and snippets.

@colgraff
colgraff / InitStructFromData.swift
Last active August 19, 2017 22:10 — forked from ryantxr/InitStructFromData.swift
Initialize a struct from data, dictionary etc
// Credit: https://stackoverflow.com/users/887210/colgraff
struct Header {
let version : UInt
let options : UInt
let records : UInt
}
// adds marshaling
extension Header {
enum Keys: String { case version, options, records }
import Foundation
// Get input from the user
func getInput() -> String? {
print("\nDice: ", terminator: "")
guard let newInput = readLine()?.lowercased() else { return nil }
if newInput == "q" {
print("Thanks for rolling with me!")
exit(EXIT_SUCCESS)