-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Rx string limiting extensions #130
base: master
Are you sure you want to change the base?
Conversation
Can it be made into a extension ControlPropertyType where E == String {
public var stripReturns: ControlProperty<String> {
let values: Observable<String> = asObservable().map { $0.replacingOccurrences(of: "\n", with: "") }
let valueSink: AnyObserver<String> = mapObserver { $0 }
return ControlProperty<String>(values: values, valueSink: valueSink)
}
} so that it could be used like this: titleField.textView.rx.text.orEmpty.stripReturns <-> viewModel.opportunityTitle >>> rx_disposeBag |
extension String { | ||
func ip_trimmed(toLength length: Int) -> String { | ||
if ip_length > length { | ||
return substring(to: index(startIndex, offsetBy: length)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swift 3 has a prefix
method that is slightly shorter. See
"The New Substring Type" in https://www.swiftbysundell.com/posts/exploring-the-new-string-api-in-swift-4 for Swift 3 and Swift 4 ways to do this.
8b2aa90
to
f390a8a
Compare
f390a8a
to
e9dee42
Compare
Generated by 🚫 Danger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebase and
@mayasaxena Do you still want this in? Or would you like us to close this pull request? |
@paulrolfe If we still think it's useful I can update and merge |
@mayasaxena That would be great, please do! Thanks |
String
extension for trimming to specified lengthObservableType
extensions for limiting length of optional and non-optional StringsReactive
extension for limiting length ofUITextField
input