property wrappers

This commit is contained in:
Pfeil, Scott Robert 2020-01-08 13:11:11 -05:00
parent 6f6575c43e
commit 7c1bef990b
3 changed files with 62 additions and 0 deletions

View File

@ -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 = "<group>"; };
D282AAB52240085300C46919 /* MVMCoreGetterUtility+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MVMCoreGetterUtility+Extension.swift"; sourceTree = "<group>"; };
D282AAB72240342D00C46919 /* NSNumber+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSNumber+Extension.swift"; sourceTree = "<group>"; };
D2DEDCB623C63F3B00C44CC4 /* Clamping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Clamping.swift; sourceTree = "<group>"; };
D2DEDCB823C6400600C44CC4 /* UnitInterval.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnitInterval.swift; sourceTree = "<group>"; };
D2E1FAD82260C3E400AEFD8C /* DelegateObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DelegateObject.swift; sourceTree = "<group>"; };
/* 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 = "<group>";
};
D2DEDCB523C63F1800C44CC4 /* PropertyWrappers */ = {
isa = PBXGroup;
children = (
D2DEDCB623C63F3B00C44CC4 /* Clamping.swift */,
D2DEDCB823C6400600C44CC4 /* UnitInterval.swift */,
);
path = PropertyWrappers;
sourceTree = "<group>";
};
/* 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 */,

View File

@ -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<Value: Comparable> {
private var value: Value
private let range: ClosedRange<Value>
init(range: ClosedRange<Value>) {
self.value = range.lowerBound
self.range = range
}
public var wrappedValue: Value {
get { value }
set { value = min(max(range.lowerBound, newValue), range.upperBound) }
}
}

View File

@ -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<Value: FloatingPoint> {
@Clamping(range: 0...1)
public var wrappedValue: Value
public init(wrappedValue value: Value) {
self.wrappedValue = value
}
}