-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from orchetect/dev
Dev merge
- Loading branch information
Showing
66 changed files
with
1,513 additions
and
1,317 deletions.
There are no files selected for viewing
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
114 changes: 114 additions & 0 deletions
114
Sources/OTCore/Abstractions/Clamped Property Wrapper.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// | ||
// Clamped Property Wrapper.swift | ||
// OTCore • https://github.com/orchetect/OTCore | ||
// | ||
|
||
import Foundation | ||
|
||
/// **OTCore:** | ||
/// Property wrapper that clamps the wrapped value to a given range. | ||
@propertyWrapper | ||
public struct Clamped<Value> where Value : Comparable { | ||
|
||
var min: Value? | ||
var max: Value? | ||
private var value: Value | ||
|
||
public var wrappedValue: Value { | ||
get { | ||
value | ||
} | ||
set { | ||
value = Self.clamping(newValue, min: min, max: max) | ||
} | ||
} | ||
|
||
internal static func clamping(_ value: Value, | ||
min: Value?, | ||
max: Value?) -> Value { | ||
|
||
if let min = min { | ||
if let max = max { | ||
return value.clamped(to: min...max) | ||
} else { | ||
return value.clamped(to: min...) | ||
} | ||
} else if let max = max { | ||
return value.clamped(to: ...max) | ||
} else { | ||
return value | ||
} | ||
|
||
} | ||
|
||
public init(wrappedValue defaultValue: Value, | ||
to range: ClosedRange<Value>) { | ||
|
||
let formRange = range.absoluteBounds | ||
|
||
self.min = formRange.min | ||
self.max = formRange.max | ||
|
||
self.value = Self.clamping(defaultValue, | ||
min: formRange.min, | ||
max: formRange.max) | ||
|
||
} | ||
|
||
public init(wrappedValue defaultValue: Value, | ||
to range: Range<Value>) where Value : Strideable { | ||
|
||
let formRange = range.absoluteBounds | ||
|
||
self.min = formRange.min | ||
self.max = formRange.max | ||
|
||
self.value = Self.clamping(defaultValue, | ||
min: formRange.min, | ||
max: formRange.max) | ||
|
||
} | ||
|
||
public init(wrappedValue defaultValue: Value, | ||
to range: PartialRangeUpTo<Value>) where Value : Strideable { | ||
|
||
let formRange = range.absoluteBounds | ||
|
||
self.min = formRange.min | ||
self.max = formRange.max | ||
|
||
self.value = Self.clamping(defaultValue, | ||
min: formRange.min, | ||
max: formRange.max) | ||
|
||
} | ||
|
||
public init(wrappedValue defaultValue: Value, | ||
to range: PartialRangeThrough<Value>) { | ||
|
||
let formRange = range.absoluteBounds | ||
|
||
self.min = formRange.min | ||
self.max = formRange.max | ||
|
||
self.value = Self.clamping(defaultValue, | ||
min: formRange.min, | ||
max: formRange.max) | ||
|
||
} | ||
|
||
public init(wrappedValue defaultValue: Value, | ||
to range: PartialRangeFrom<Value>) { | ||
|
||
let formRange = range.absoluteBounds | ||
|
||
self.min = formRange.min | ||
self.max = formRange.max | ||
|
||
self.value = Self.clamping(defaultValue, | ||
min: formRange.min, | ||
max: formRange.max) | ||
|
||
} | ||
|
||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ extension String { | |
|
||
/// **OTCore:** | ||
/// Returns true if the string is a valid email address. | ||
@_disfavoredOverload | ||
public var isValidEmailAddress: Bool { | ||
|
||
// [email protected] | ||
|
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
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
Oops, something went wrong.