X-Git-Url: https://git.mdrn.pl/wl-app.git/blobdiff_plain/53b27422d140022594fc241cca91c3183be57bca..48b2fe9f7c2dc3d9aeaaa6dbfb27c7da4f3235ff:/iOS/WolneLektury/Model/ReadingStateModel.swift diff --git a/iOS/WolneLektury/Model/ReadingStateModel.swift b/iOS/WolneLektury/Model/ReadingStateModel.swift new file mode 100644 index 0000000..0ff9f05 --- /dev/null +++ b/iOS/WolneLektury/Model/ReadingStateModel.swift @@ -0,0 +1,44 @@ +// +// ReadingStateModel.swift +// WolneLektury +// +// Created by Pawel Dabrowski on 29/08/2018. +// Copyright © 2018 Fundacja Nowoczesna Polska. All rights reserved. +// + +import UIKit + +class ReadingStateModel: Decodable{ + + public enum ReadingState : String { + case unknown = "unknown" + case not_started = "not_started" + case reading = "reading" + case complete = "complete" + } + + var state = ReadingState.unknown + + private enum ReadingStateModelCodingKeys: String, CodingKey { + case state + } + + convenience required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: ReadingStateModelCodingKeys.self) + + let stateString = try container.decode(String.self, forKey: .state) + + var returnState: ReadingState = .unknown + + if let readingState = ReadingState(rawValue: stateString) { + returnState = readingState + } + + self.init(state: returnState) + } + + convenience init(state: ReadingState) { + self.init() + self.state = state + } +}