Skip to content
This repository has been archived by the owner on Oct 22, 2020. It is now read-only.

Commit

Permalink
Fixing issue with ObjC compatibility for plain text validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Eri committed Sep 5, 2016
1 parent 98e3d4b commit 9402d75
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion BMInputBox.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

Pod::Spec.new do |s|
s.name = "BMInputBox"
s.version = "1.2.2"
s.version = "1.2.3"
s.summary = "Drop-in replacement for the limited UIAlertView input options."
s.description = <<-DESC
BMInputBox is an iOS drop-in class wrote in Swift that displays input boxes for the user to input different kinds of data, for instance username and password, email address, numbers, plain text. BMInputBox is meant as a replacement for the limited UIAlertView input options.
Expand Down
24 changes: 12 additions & 12 deletions Pod/Classes/BMInputBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public class BMInputBox: UIView {
Customisation of the PlainText type
*/
/// Maximum length of the text. If set, the entered text's length will be checked against this.
public var maximumLength: Int?
public var maximumLength: Int = 0

/// Minimum length of the text. If set, the entered text's length will be checked against this.
public var minimumLength: Int?
public var minimumLength: Int = 0

/**
String used to notify the user about the value critera (minimum and maximum values).
Expand Down Expand Up @@ -289,18 +289,18 @@ public class BMInputBox: UIView {

let messageString: String? = self.validationLabelText

if (self.minimumLength != nil && self.maximumLength == nil) {
self.validationLabel.text = String(format: messageString ?? "A text longer than %i characters.", self.minimumLength!) as String
if (self.minimumLength != 0 && self.maximumLength == 0) {
self.validationLabel.text = String(format: messageString ?? "A text longer than %i characters.", self.minimumLength) as String
}
else if (self.minimumLength == nil && self.maximumLength != nil) {
self.validationLabel.text = String(format: messageString ?? "A text shorter than %i characters.", self.maximumLength!) as String
else if (self.minimumLength == 0 && self.maximumLength != 0) {
self.validationLabel.text = String(format: messageString ?? "A text shorter than %i characters.", self.maximumLength) as String
}
else if (self.minimumLength != nil && self.maximumLength != nil) {
else if (self.minimumLength != 0 && self.maximumLength != 0) {

if (self.minimumLength == self.maximumLength) {
self.validationLabel.text = String(format: messageString ?? "A text exactly %i characters long.", self.minimumLength!) as String
self.validationLabel.text = String(format: messageString ?? "A text exactly %i characters long.", self.minimumLength) as String
} else {
self.validationLabel.text = String(format: messageString ?? "A text between %i and %i characters.", self.minimumLength!, self.maximumLength!) as String
self.validationLabel.text = String(format: messageString ?? "A text between %i and %i characters.", self.minimumLength, self.maximumLength) as String
}
}

Expand Down Expand Up @@ -489,20 +489,20 @@ public class BMInputBox: UIView {
/**
* Validating the plain text input. Lenght of the text.
*/
if self.style == .PlainTextInput && (self.minimumLength != nil || self.maximumLength != nil) {
if self.style == .PlainTextInput && (self.minimumLength != 0 || self.maximumLength != 0) {
if self.textInput?.text == "" {
return false
}

// Lower than minimum value
if self.minimumLength != nil {
if self.minimumLength != 0 {
if self.minimumLength > self.textInput!.text!.characters.count {
return false
}
}

// Greater maximum value
if self.maximumLength != nil {
if self.maximumLength != 0 {
if self.maximumLength < self.textInput!.text!.characters.count {
return false
}
Expand Down

0 comments on commit 9402d75

Please sign in to comment.