-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3dd552d
commit 522c16a
Showing
4 changed files
with
62 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,4 @@ SPEC CHECKSUMS: | |
|
||
PODFILE CHECKSUM: d81cbe2f98140887848195204b8b667819be7198 | ||
|
||
COCOAPODS: 1.3.1 | ||
COCOAPODS: 1.4.0 |
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
19 changes: 19 additions & 0 deletions
19
SwiftWisdom/Core/StandardLibrary/String/String+Trimmed.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,19 @@ | ||
// | ||
// String+Trimmed.swift | ||
// SwiftWisdom | ||
// | ||
// Created by Maya Saxena on 6/13/17. | ||
// Copyright © 2017 Intrepid. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension String { | ||
func ip_trimmed(toLength length: Int) -> String { | ||
if ip_length > length { | ||
return substring(to: index(startIndex, offsetBy: length)) | ||
} else { | ||
return self | ||
} | ||
} | ||
} |
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,34 @@ | ||
// | ||
// Rx+String.swift | ||
// SwiftWisdom | ||
// | ||
// Created by Maya Saxena on 6/12/17. | ||
// Copyright © 2017 Intrepid. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import RxSwift | ||
|
||
extension ObservableType where E == String { | ||
public func ip_limitLength(to limit: Int) -> Observable<E> { | ||
return self.map { $0.ip_trimmed(toLength: limit) } | ||
} | ||
} | ||
|
||
extension ObservableType where E == String? { | ||
public func ip_limitLength(to limit: Int) -> Observable<E> { | ||
return self.map { $0?.ip_trimmed(toLength: limit) } | ||
} | ||
} | ||
|
||
extension Reactive where Base: UITextField { | ||
/** Limit the length of input to a text field | ||
|
||
Usage Example: | ||
|
||
textField.rx.ip_limitLength(to: 5) | ||
*/ | ||
public func ip_limitLength(to limit: Int) -> Disposable { | ||
return text.ip_limitLength(to: limit).bind(to: text) | ||
} | ||
} |