-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
759 additions
and
595 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// SketchMetadata.swift | ||
// StyleSync | ||
// | ||
// Created by Dylan Lewis on 12/05/2018. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct SketchMetadata: Codable { | ||
public let appVersion: Version | ||
|
||
// MARK: - Codable | ||
|
||
public init(from decoder: Decoder) throws { | ||
let values = try decoder.container(keyedBy: CodingKeys.self) | ||
let versionString = try values.decode(String.self, forKey: .appVersionString) | ||
guard let version = Version(versionString: versionString) else { | ||
throw Error.failedToCreateVersion(versionString: versionString) | ||
} | ||
self.appVersion = version | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
try container.encode(appVersion.stringRepresentation, forKey: .appVersionString) | ||
} | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case appVersionString = "appVersion" | ||
} | ||
} | ||
|
||
// MARK: - Error | ||
|
||
extension SketchMetadata { | ||
enum Error: Swift.Error, CustomStringConvertible { | ||
case failedToCreateVersion(versionString: String) | ||
|
||
var description: String { | ||
switch self { | ||
case .failedToCreateVersion(let versionString): | ||
return "Failed to create Version from \(versionString)" | ||
} | ||
} | ||
} | ||
} | ||
|
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
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
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
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
Oops, something went wrong.