Skip to content

Commit

Permalink
Make public
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamad Fuad committed Apr 18, 2022
1 parent 8318a0b commit 2179cbe
Show file tree
Hide file tree
Showing 19 changed files with 493 additions and 119 deletions.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![SPM compatible](https://img.shields.io/badge/SPM-Compatible-brightgreen.svg?style=flat)](https://swift.org/package-manager/)
[![Swift](https://img.shields.io/badge/Swift-5.6-orange.svg)](https://swift.org)
[![Xcode](https://img.shields.io/badge/Xcode-13.3-blue.svg)](https://developer.apple.com/xcode)
![Issues](https://img.shields.io/github/issues/ihamadfuad/PropertyWrapperAPI) ![Releases](https://img.shields.io/github/v/release/ihamadfuad/PropertyWrapperAPI)

# Sponsor
[![Sponsor](https://img.shields.io/badge/Donate-PayPal-blue.svg)](https://paypal.me/nuralme?country.x=BH&locale.x=en_US)

# PropertyWrapperAPI

A description of this package.
A collaborative list of awesome Swift Proprty Wrappers.

## Installation
### Swift Package Manager (SPM)

You can use The Swift Package Manager to install PropertyWrapperAPI by adding it to your Package.swift file:

import PackageDescription

let package = Package(
name: "MyApp",
targets: [],
dependencies: [
.Package(url: "https://github.com/ihamadfuad/PropertyWrapperAPI.git", .from: "1.0.0")
]
)
26 changes: 23 additions & 3 deletions Sources/PropertyWrapperAPI/AppThemeTextField.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@

// ºººº----------------------------------------------------------------------ºººº \\
//
// Copyright (c) 2022 Hamad Fuad.
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
// associated documentation files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial
// portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// AppThemeTextField.swift
//
// Author: Hamad Fuad
// Email: ihamadfouad@icloud.com
//
// Created by Hamad Ali on 18/04/2022.
// Created At: 18/04/2022
// Last modified: 18/04/2022
//
// ºººº----------------------------------------------------------------------ºººº \\

import SwiftUI

Expand Down
38 changes: 29 additions & 9 deletions Sources/PropertyWrapperAPI/Appending.swift
Original file line number Diff line number Diff line change
@@ -1,44 +1,64 @@

// ºººº----------------------------------------------------------------------ºººº \\
//
// Copyright (c) 2022 Hamad Fuad.
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
// associated documentation files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial
// portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Appending.swift
//
// Author: Hamad Fuad
// Email: ihamadfouad@icloud.com
//
// Created by Hamad Ali on 18/04/2022.
// Created At: 18/04/2022
// Last modified: 18/04/2022
//
// ºººº----------------------------------------------------------------------ºººº \\

import Foundation

protocol Appendable {
public protocol Appendable {

func appending(string: String) -> Self
}

extension String: Appendable {

func appending(string: String) -> String {
public func appending(string: String) -> String {
return self + string
}
}

@propertyWrapper
struct Appending<T: Appendable> {
public struct Appending<T: Appendable> {

private(set) var value: T
let toAppend: String

var wrappedValue: T {
public var wrappedValue: T {
get { value }
set { value = newValue.appending(string: toAppend) }
}

init(wrappedValue: T, _ toAppend: String) {
public init(wrappedValue: T, _ toAppend: String) {
self.value = wrappedValue
self.toAppend = toAppend
}
}

extension Appending: Appendable {

func appending(string: String) -> Appending<T> {
public func appending(string: String) -> Appending<T> {
return Appending(
wrappedValue: self.wrappedValue.appending(
string: string
Expand Down
36 changes: 30 additions & 6 deletions Sources/PropertyWrapperAPI/Base64Encoding.swift
Original file line number Diff line number Diff line change
@@ -1,19 +1,43 @@

// ºººº----------------------------------------------------------------------ºººº \\
//
// Copyright (c) 2022 Hamad Fuad.
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
// associated documentation files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial
// portions of the Software.
//
// Base64Encoding.swift
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Created by Hamad Ali on 18/04/2022.
// Author: Hamad Fuad
// Email: ihamadfouad@icloud.com
//
// Created At: 18/04/2022
// Last modified: 18/04/2022
//
// ºººº----------------------------------------------------------------------ºººº \\

import Foundation

@propertyWrapper
struct Base64Encoding {
public struct Base64Encoding {

private var value = ""
var value = ""

var wrappedValue: String {
public var wrappedValue: String {
get { Data(value.utf8).base64EncodedString() }
set { value = newValue }
}

public init(wrappedValue: String) {
self.wrappedValue = wrappedValue
}
}
31 changes: 25 additions & 6 deletions Sources/PropertyWrapperAPI/Capitalized.swift
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
// ºººº----------------------------------------------------------------------ºººº \\
//
// Capitalized.swift
//
// Copyright (c) 2022 Hamad Fuad.
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
// associated documentation files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// Created by Hamad Ali on 18/04/2022.
// The above copyright notice and this permission notice shall be included in all copies or substantial
// portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Author: Hamad Fuad
// Email: ihamadfouad@icloud.com
//
// Created At: 18/04/2022
// Last modified: 18/04/2022
//
// ºººº----------------------------------------------------------------------ºººº \\

import Foundation

@propertyWrapper struct Capitalized {
@propertyWrapper public struct Capitalized {

var wrappedValue: String {
public var wrappedValue: String {

didSet {
wrappedValue = wrappedValue.capitalized
}
}

init(wrappedValue: String) {
public init(wrappedValue: String) {

self.wrappedValue = wrappedValue.capitalized
}
Expand Down
32 changes: 26 additions & 6 deletions Sources/PropertyWrapperAPI/Constrained.swift
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@

// ºººº----------------------------------------------------------------------ºººº \\
//
// Copyright (c) 2022 Hamad Fuad.
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
// associated documentation files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial
// portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Constrained.swift
//
// Author: Hamad Fuad
// Email: ihamadfouad@icloud.com
//
// Created by Hamad Ali on 18/04/2022.
// Created At: 18/04/2022
// Last modified: 18/04/2022
//
// ºººº----------------------------------------------------------------------ºººº \\

import Foundation

@propertyWrapper
struct Constrained<Value: Comparable> {
public struct Constrained<Value: Comparable> {

private var range: ClosedRange<Value>
private var value: Value

init(wrappedValue value: Value, _ range: ClosedRange<Value>) {
public init(wrappedValue value: Value, _ range: ClosedRange<Value>) {
self.value = value
self.range = range
}

var wrappedValue: Value {
public var wrappedValue: Value {
get {
return max(min(value, range.upperBound), range.lowerBound)
}
Expand Down
32 changes: 26 additions & 6 deletions Sources/PropertyWrapperAPI/Consumable.swift
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@

// ºººº----------------------------------------------------------------------ºººº \\
//
// Copyright (c) 2022 Hamad Fuad.
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
// associated documentation files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial
// portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Consumable.swift
//
// Author: Hamad Fuad
// Email: ihamadfouad@icloud.com
//
// Created by Hamad Ali on 18/04/2022.
// Created At: 18/04/2022
// Last modified: 18/04/2022
//
// ºººº----------------------------------------------------------------------ºººº \\

import Foundation

/// Creates a value that can only be accessed once.
/// Accessing the value will consume and clear the value.
@propertyWrapper
enum Consumable<Value> {
public enum Consumable<Value> {

case unused(Value?)
case used

init(wrappedValue: Value?) {
public init(wrappedValue: Value?) {
self = .unused(wrappedValue)
}

var wrappedValue: Value? {
public var wrappedValue: Value? {
mutating get {
switch self {
case .unused(let value):
Expand Down
31 changes: 25 additions & 6 deletions Sources/PropertyWrapperAPI/EmailValidation.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
// ºººº----------------------------------------------------------------------ºººº \\
//
// EmailValidation.swift
//
// Copyright (c) 2022 Hamad Fuad.
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
// associated documentation files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// Created by Hamad Ali on 18/04/2022.
// The above copyright notice and this permission notice shall be included in all copies or substantial
// portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Author: Hamad Fuad
// Email: ihamadfouad@icloud.com
//
// Created At: 18/04/2022
// Last modified: 18/04/2022
//
// ºººº----------------------------------------------------------------------ºººº \\

import Foundation

@propertyWrapper
struct Email<Value: StringProtocol> {
public struct Email<Value: StringProtocol> {

var value: Value?

var wrappedValue: Value? {
public var wrappedValue: Value? {
get {
return validate(email: value) ? value : nil
}
Expand All @@ -21,7 +40,7 @@ struct Email<Value: StringProtocol> {
}
}

init(wrappedValue value: Value?) {
public init(wrappedValue value: Value?) {
self.value = value
}

Expand Down

0 comments on commit 2179cbe

Please sign in to comment.