Created
February 1, 2018 22:51
-
-
Save tmspzz/0af45021f559f17055d2ce8abb792c1e to your computer and use it in GitHub Desktop.
Derive Codable2
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
import Foundation | |
public struct CaseInsensitiveString: Codable { | |
let value: String | |
public init(caseInsensitiveString: CaseInsensitiveString) { | |
self.value = caseInsensitiveString.value | |
} | |
} | |
extension CaseInsensitiveString: ExpressibleByStringLiteral { | |
public typealias StringLiteralType = String | |
public init(unicodeScalarLiteral value: UnicodeScalar) { | |
self.value = "\(value)" | |
} | |
public init(extendedGraphemeClusterLiteral value: String) { | |
self.value = value | |
} | |
public init(stringLiteral value: String) { | |
self.value = value | |
} | |
} | |
extension CaseInsensitiveString: CustomStringConvertible { | |
public var description: String { | |
return self.value | |
} | |
} | |
extension CaseInsensitiveString: StringInterpolationConvertible { | |
public init(stringInterpolation strings: CaseInsensitiveString...) { | |
self.value = strings.reduce("") { acc, cis in let newAcc = acc+cis.description; return newAcc } | |
} | |
public init<T>(stringInterpolationSegment expr: T) { | |
self.value = "\(expr)" | |
} | |
} | |
extension CaseInsensitiveString: Equatable { } | |
public func ==(lhs: CaseInsensitiveString, rhs: CaseInsensitiveString) -> Bool { | |
return lhs.value.caseInsensitiveCompare(rhs.value) == ComparisonResult.orderedSame | |
} | |
public func +(lhs: CaseInsensitiveString, rhs: CaseInsensitiveString) -> CaseInsensitiveString { | |
return CaseInsensitiveString(stringLiteral: lhs.value + rhs.value) | |
} | |
public enum ItemSourceType: CaseInsensitiveString, Codable { | |
case event = "EVENT" // This we don't have | |
case topic = "FollowedTopic" | |
case gd = "GD" // This we don't have | |
case rat = "RealAge" | |
case campaign = "Campaign" | |
case general = "General" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment