added colorcodable
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
2a1f3c9e33
commit
4dcddd7fef
@ -43,6 +43,7 @@
|
||||
EA3362452892F9130071C351 /* Labelable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3362442892F9130071C351 /* Labelable.swift */; };
|
||||
EA33624728931B050071C351 /* Initable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA33624628931B050071C351 /* Initable.swift */; };
|
||||
EA3C3B4C2894823E000CA526 /* AnyProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3C3B4B2894823E000CA526 /* AnyProxy.swift */; };
|
||||
EA84F6B128B94A2500D67ABC /* CodableColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA84F6B028B94A2500D67ABC /* CodableColor.swift */; };
|
||||
EA89200228AECF2A006B9984 /* UIButton+Publisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA89200128AECF2A006B9984 /* UIButton+Publisher.swift */; };
|
||||
EA89200428AECF4B006B9984 /* UITextField+Publisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA89200328AECF4B006B9984 /* UITextField+Publisher.swift */; };
|
||||
EA89200628B526D6006B9984 /* CheckboxGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA89200528B526D6006B9984 /* CheckboxGroup.swift */; };
|
||||
@ -139,6 +140,7 @@
|
||||
EA3362442892F9130071C351 /* Labelable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Labelable.swift; sourceTree = "<group>"; };
|
||||
EA33624628931B050071C351 /* Initable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Initable.swift; sourceTree = "<group>"; };
|
||||
EA3C3B4B2894823E000CA526 /* AnyProxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyProxy.swift; sourceTree = "<group>"; };
|
||||
EA84F6B028B94A2500D67ABC /* CodableColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodableColor.swift; sourceTree = "<group>"; };
|
||||
EA89200128AECF2A006B9984 /* UIButton+Publisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIButton+Publisher.swift"; sourceTree = "<group>"; };
|
||||
EA89200328AECF4B006B9984 /* UITextField+Publisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITextField+Publisher.swift"; sourceTree = "<group>"; };
|
||||
EA89200528B526D6006B9984 /* CheckboxGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckboxGroup.swift; sourceTree = "<group>"; };
|
||||
@ -411,8 +413,9 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
EA3C3B4B2894823E000CA526 /* AnyProxy.swift */,
|
||||
EAB1D2A028A598FE00DAE764 /* UsesAutoLayout.swift */,
|
||||
EA84F6B028B94A2500D67ABC /* CodableColor.swift */,
|
||||
EAB1D2A228A5994800DAE764 /* Debuggable.swift */,
|
||||
EAB1D2A028A598FE00DAE764 /* UsesAutoLayout.swift */,
|
||||
);
|
||||
path = PropertyWrappers;
|
||||
sourceTree = "<group>";
|
||||
@ -596,6 +599,7 @@
|
||||
EA89200D28B530FD006B9984 /* RadioBoxModel.swift in Sources */,
|
||||
EA1F266728B945070033E859 /* RadioSwatchModel.swift in Sources */,
|
||||
EA89201328B568D8006B9984 /* RadioBox.swift in Sources */,
|
||||
EA84F6B128B94A2500D67ABC /* CodableColor.swift in Sources */,
|
||||
EA3362402892EF6C0071C351 /* Label.swift in Sources */,
|
||||
EAF7F0B3289B1ADC00B287F5 /* LabelAttributeAction.swift in Sources */,
|
||||
EA33622E2891EA3C0071C351 /* DispatchQueue+Once.swift in Sources */,
|
||||
|
||||
57
VDS/PropertyWrappers/CodableColor.swift
Normal file
57
VDS/PropertyWrappers/CodableColor.swift
Normal file
@ -0,0 +1,57 @@
|
||||
//
|
||||
// CodableColor.swift
|
||||
// VDS
|
||||
//
|
||||
// Created by Matt Bruce on 8/26/22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
@propertyWrapper
|
||||
public struct CodableColor {
|
||||
public var wrappedValue: UIColor
|
||||
|
||||
public init(wrappedValue: UIColor) {
|
||||
self.wrappedValue = wrappedValue
|
||||
}
|
||||
}
|
||||
|
||||
extension CodableColor: Codable {
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.singleValueContainer()
|
||||
let colorString = try container.decode(String.self)
|
||||
wrappedValue = UIColor(hexString: colorString)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.singleValueContainer()
|
||||
try container.encode(wrappedValue.hexString)
|
||||
}
|
||||
}
|
||||
|
||||
@propertyWrapper
|
||||
public struct OptionalCodableColor {
|
||||
public var wrappedValue: UIColor?
|
||||
|
||||
public init(wrappedValue: UIColor?) {
|
||||
self.wrappedValue = wrappedValue
|
||||
}
|
||||
}
|
||||
|
||||
extension OptionalCodableColor: Codable {
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.singleValueContainer()
|
||||
if container.decodeNil() {
|
||||
wrappedValue = nil
|
||||
} else {
|
||||
let colorString = try container.decode(String.self)
|
||||
wrappedValue = UIColor(hexString: colorString)
|
||||
}
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.singleValueContainer()
|
||||
try container.encode(wrappedValue?.hexString)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user