From e2885b0f78c5906e1349389822e31e5c5c469899 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 8 Jan 2020 14:27:11 -0500 Subject: [PATCH] Percent --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 4 +++ .../Utility/PropertyWrappers/Percent.swift | 31 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 MVMCore/MVMCore/Utility/PropertyWrappers/Percent.swift diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index 68c281d..57a110b 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -159,6 +159,7 @@ D282AAB82240342D00C46919 /* NSNumber+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AAB72240342D00C46919 /* NSNumber+Extension.swift */; }; D2DEDCB723C63F3B00C44CC4 /* Clamping.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2DEDCB623C63F3B00C44CC4 /* Clamping.swift */; }; D2DEDCB923C6400600C44CC4 /* UnitInterval.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2DEDCB823C6400600C44CC4 /* UnitInterval.swift */; }; + D2DEDCBB23C65BC300C44CC4 /* Percent.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2DEDCBA23C65BC300C44CC4 /* Percent.swift */; }; D2E1FAD92260C3E400AEFD8C /* DelegateObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E1FAD82260C3E400AEFD8C /* DelegateObject.swift */; }; /* End PBXBuildFile section */ @@ -309,6 +310,7 @@ D282AAB72240342D00C46919 /* NSNumber+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSNumber+Extension.swift"; sourceTree = ""; }; D2DEDCB623C63F3B00C44CC4 /* Clamping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Clamping.swift; sourceTree = ""; }; D2DEDCB823C6400600C44CC4 /* UnitInterval.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnitInterval.swift; sourceTree = ""; }; + D2DEDCBA23C65BC300C44CC4 /* Percent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Percent.swift; sourceTree = ""; }; D2E1FAD82260C3E400AEFD8C /* DelegateObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DelegateObject.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -688,6 +690,7 @@ children = ( D2DEDCB623C63F3B00C44CC4 /* Clamping.swift */, D2DEDCB823C6400600C44CC4 /* UnitInterval.swift */, + D2DEDCBA23C65BC300C44CC4 /* Percent.swift */, ); path = PropertyWrappers; sourceTree = ""; @@ -930,6 +933,7 @@ 946EE1B4237B619D0036751F /* Encoder.swift in Sources */, AFBB96941FBA3A9A0008D868 /* MVMCorePresentAnimationOperation.m in Sources */, AF43A5841FBB66DE008E9347 /* MVMCoreConstants.m in Sources */, + D2DEDCBB23C65BC300C44CC4 /* Percent.swift in Sources */, AFBB966A1FBA3A570008D868 /* MVMCoreLoadRequestOperation.m in Sources */, 8876D5F31FB50AB000EB2E3D /* UIFont+MFSpacing.m in Sources */, D282AAB82240342D00C46919 /* NSNumber+Extension.swift in Sources */, diff --git a/MVMCore/MVMCore/Utility/PropertyWrappers/Percent.swift b/MVMCore/MVMCore/Utility/PropertyWrappers/Percent.swift new file mode 100644 index 0000000..2116306 --- /dev/null +++ b/MVMCore/MVMCore/Utility/PropertyWrappers/Percent.swift @@ -0,0 +1,31 @@ +// +// Progress.swift +// MVMCore +// +// Created by Scott Pfeil on 1/8/20. +// Copyright © 2020 myverizon. All rights reserved. +// + +import Foundation + +@propertyWrapper +public struct Percent { + @Clamping(range: 0...100) + public var wrappedValue: CGFloat + + public init(wrappedValue value: CGFloat) { + self.wrappedValue = value + } +} + +extension Percent: Codable { + public init(from decoder: Decoder) throws { + let typeContainer = try decoder.singleValueContainer() + self.wrappedValue = try typeContainer.decode(CGFloat.self) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(wrappedValue) + } +}