diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index 0e4cad7..26f0ec2 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -149,6 +149,8 @@ AFFCFA681FCCC0D700FD0730 /* MVMCoreLoadingViewControllerProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = AFFCFA641FCCC0D600FD0730 /* MVMCoreLoadingViewControllerProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; D282AAB62240085300C46919 /* MVMCoreGetterUtility+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AAB52240085300C46919 /* MVMCoreGetterUtility+Extension.swift */; }; 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 */; }; D2E1FAD92260C3E400AEFD8C /* DelegateObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E1FAD82260C3E400AEFD8C /* DelegateObject.swift */; }; /* End PBXBuildFile section */ @@ -289,6 +291,8 @@ AFFCFA641FCCC0D600FD0730 /* MVMCoreLoadingViewControllerProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreLoadingViewControllerProtocol.h; sourceTree = ""; }; D282AAB52240085300C46919 /* MVMCoreGetterUtility+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MVMCoreGetterUtility+Extension.swift"; sourceTree = ""; }; 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 = ""; }; D2E1FAD82260C3E400AEFD8C /* DelegateObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DelegateObject.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -353,6 +357,7 @@ 881D26901FCC9D180079C521 /* MVMCoreOperation.m */, AFEA17A6209B6A1C00BC6740 /* MVMCoreBlockOperation.h */, AFEA17A7209B6A1C00BC6740 /* MVMCoreBlockOperation.m */, + D2DEDCB523C63F1800C44CC4 /* PropertyWrappers */, AFBB96E71FBA4A260008D868 /* HardCodedServerResponse */, AFBB96AB1FBA3B590008D868 /* Helpers */, ); @@ -654,6 +659,15 @@ path = LoadingOverlay; sourceTree = ""; }; + D2DEDCB523C63F1800C44CC4 /* PropertyWrappers */ = { + isa = PBXGroup; + children = ( + D2DEDCB623C63F3B00C44CC4 /* Clamping.swift */, + D2DEDCB823C6400600C44CC4 /* UnitInterval.swift */, + ); + path = PropertyWrappers; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -850,6 +864,7 @@ 881D26931FCC9D180079C521 /* MVMCoreErrorObject.m in Sources */, 946EE1B0237B5EF70036751F /* JSONHelper.swift in Sources */, 30349BF21FCCA78A00546A1E /* MVMCoreSessionTimeHandler.m in Sources */, + D2DEDCB923C6400600C44CC4 /* UnitInterval.swift in Sources */, 8876D5E91FB50AB000EB2E3D /* NSArray+MFConvenience.m in Sources */, 946EE1B2237B5F260036751F /* JSONValue.swift in Sources */, AFBB96971FBA3A9A0008D868 /* MVMCorePresentViewControllerOperation.m in Sources */, @@ -870,6 +885,7 @@ 8876D5F51FB50AB000EB2E3D /* UILabel+MFCustom.m in Sources */, AFBB96B31FBA3B590008D868 /* MVMCoreGetterUtility.m in Sources */, AF43A7071FC4D7A2008E9347 /* MVMCoreObject.m in Sources */, + D2DEDCB723C63F3B00C44CC4 /* Clamping.swift in Sources */, 01DF561421F90ADC00CC099B /* Dictionary+MFConvenience.swift in Sources */, AFBB96B11FBA3B590008D868 /* MVMCoreDispatchUtility.m in Sources */, 946EE1A3237B59C30036751F /* Model.swift in Sources */, diff --git a/MVMCore/MVMCore/Utility/PropertyWrappers/Clamping.swift b/MVMCore/MVMCore/Utility/PropertyWrappers/Clamping.swift new file mode 100644 index 0000000..06008f9 --- /dev/null +++ b/MVMCore/MVMCore/Utility/PropertyWrappers/Clamping.swift @@ -0,0 +1,26 @@ +// +// Clamping.swift +// MVMCore +// +// Created by Scott Pfeil on 1/8/20. +// Copyright © 2020 myverizon. All rights reserved. +// +// Clamps the value between a given range. + +import Foundation + +@propertyWrapper +public struct Clamping { + private var value: Value + private let range: ClosedRange + + init(range: ClosedRange) { + self.value = range.lowerBound + self.range = range + } + + public var wrappedValue: Value { + get { value } + set { value = min(max(range.lowerBound, newValue), range.upperBound) } + } +} diff --git a/MVMCore/MVMCore/Utility/PropertyWrappers/UnitInterval.swift b/MVMCore/MVMCore/Utility/PropertyWrappers/UnitInterval.swift new file mode 100644 index 0000000..cf25308 --- /dev/null +++ b/MVMCore/MVMCore/Utility/PropertyWrappers/UnitInterval.swift @@ -0,0 +1,20 @@ +// +// UnitInterval.swift +// MVMCore +// +// Created by Scott Pfeil on 1/8/20. +// Copyright © 2020 myverizon. All rights reserved. +// +// Clamps the value between 0 and 1 + +import Foundation + +@propertyWrapper +public struct UnitInterval { + @Clamping(range: 0...1) + public var wrappedValue: Value + + public init(wrappedValue value: Value) { + self.wrappedValue = value + } +}