Swiftpack.co - xattacker/RequiredPropertyChecker as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by xattacker.
xattacker/RequiredPropertyChecker 1.0.0
a Combine related component, help checking property has been filled
⭐️ 0
🕓 1 year ago
iOS
.package(url: "https://github.com/xattacker/RequiredPropertyChecker.git", from: "1.0.0")

RequiredPropertyChecker

a Swift Combine Related component, help checking property has been filled

another congeneric project: https://github.com/xattacker/RxRequiredPropertyChecker
(which implemented by RxSwift)

Demo Video

https://user-images.githubusercontent.com/33754378/185822595-a259f689-4b87-48d2-9416-7f23dd29ea7d.mp4

Installation

Cocoapods

RequiredPropertyChecker can be added to your project using CocoaPods 0.36 or later by adding the following line to your Podfile:

pod 'RequiredPropertyChecker'

Swift Package Manager

To add RequiredPropertyChecker to a Swift Package Manager based project, add:

.package(url: "https://github.com/xattacker/RequiredPropertyChecker.git", .upToNextMajor(from: "1.0.0")),

to your Package.swift files dependencies array.

How to use:

import RequiredPropertyChecker
import Combine

// make the component implement protocol RequiredProperty
extension UITextField: RequiredProperty
{
    public var isFilled: Bool
    {
        return (self.text?.count ?? 0) > 0
    }

    public var isFilledPublisher: AnyPublisher<Bool, Never>
    {
        let p1 = NotificationCenter.default
                   .publisher(for: UITextField.textDidChangeNotification, object: self)
                   .map { (($0.object as? UITextField)?.text?.count ?? 0) > 0 }

        let p2 = self.publisher(for: \.text).map { ($0?.count ?? 0) > 0 }

        return p1.merge(with: p2).eraseToAnyPublisher()
    }
}


// then add the RequiredProperty instance into RequiredPropertyChecker
let textField: UITextField
var set = Set<AnyCancellable>()
    
let checker = RequiredPropertyChecker()
checker.add(textField)

// bind checker with other
checker.$isFilled           
            .sink {
                [weak self]
                filled in
                self?.button.isEnable = filled
            }.store(in: &set)

GitHub

link
Stars: 0
Last commit: 20 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

1.0.0
1 year ago

first release

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics