Skip to content
Snippets Groups Projects
Commit 4fef1f7f authored by Dariusz Rybicki's avatar Dariusz Rybicki
Browse files

Change type of Fact.type property to FactType

parent 0d5af7e3
Branches
Tags
2 merge requests!102Release 1.0.0,!71Fact improvements & helpers
This commit is part of merge request !71. Comments created here will be created in the context of that merge request.
...@@ -3,14 +3,14 @@ import Foundation ...@@ -3,14 +3,14 @@ import Foundation
public struct Fact: Equatable { public struct Fact: Equatable {
public init( public init(
fact: String, fact: String,
type: Int type: FactType
) { ) {
self.fact = fact self.fact = fact
self.type = type self.type = type
} }
public var fact: String public var fact: String
public var type: Int public var type: FactType
} }
extension Fact: Codable { extension Fact: Codable {
...@@ -46,13 +46,13 @@ extension Array where Element == Fact { ...@@ -46,13 +46,13 @@ extension Array where Element == Fact {
extension Array where Element == Fact { extension Array where Element == Fact {
public func get(_ type: FactType) -> Fact? { public func get(_ type: FactType) -> Fact? {
first(where: { $0.type == type.rawValue }) first(where: { $0.type == type })
} }
public mutating func set(_ type: FactType, _ value: String?) { public mutating func set(_ type: FactType, _ value: String?) {
removeAll(where: { $0.type == type.rawValue }) removeAll(where: { $0.type == type })
if let value = value { if let value = value {
append(Fact(fact: value, type: type.rawValue)) append(Fact(fact: value, type: type))
sort(by: { $0.type < $1.type }) sort(by: { $0.type < $1.type })
} }
} }
......
...@@ -5,7 +5,7 @@ import XCTest ...@@ -5,7 +5,7 @@ import XCTest
final class FactTests: XCTestCase { final class FactTests: XCTestCase {
func testCoding() throws { func testCoding() throws {
let factValue = "Zezima" let factValue = "Zezima"
let factType: Int = 0 let factType: Int = 123
let jsonString = """ let jsonString = """
{ {
"Fact": "\(factValue)", "Fact": "\(factValue)",
...@@ -17,7 +17,7 @@ final class FactTests: XCTestCase { ...@@ -17,7 +17,7 @@ final class FactTests: XCTestCase {
XCTAssertNoDifference(model, Fact( XCTAssertNoDifference(model, Fact(
fact: factValue, fact: factValue,
type: factType type: 123
)) ))
let encodedModel = try model.encode() let encodedModel = try model.encode()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment