Adding max length rule and fixing method access to make it public

This commit is contained in:
Jeff Potter 2015-04-10 10:55:04 -06:00
parent 64eed84b72
commit e09ee70c96
2 changed files with 9 additions and 5 deletions

View File

@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
623F29941AD836E6005B26CB /* MaxLengthRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 623F29931AD836E6005B26CB /* MaxLengthRule.swift */; };
628637261AAA474B00BC8FCF /* MinLengthRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 628637251AAA474B00BC8FCF /* MinLengthRule.swift */; };
628637281AAA49E300BC8FCF /* ConfirmRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 628637271AAA49E300BC8FCF /* ConfirmRule.swift */; };
62D1AE1D1A1E6D4400E4DFF8 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62D1AE1C1A1E6D4400E4DFF8 /* AppDelegate.swift */; };
@ -38,6 +39,7 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
623F29931AD836E6005B26CB /* MaxLengthRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaxLengthRule.swift; sourceTree = "<group>"; };
628637251AAA474B00BC8FCF /* MinLengthRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MinLengthRule.swift; sourceTree = "<group>"; };
628637271AAA49E300BC8FCF /* ConfirmRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConfirmRule.swift; sourceTree = "<group>"; };
62D1AE171A1E6D4400E4DFF8 /* Validator.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Validator.app; sourceTree = BUILT_PRODUCTS_DIR; };
@ -159,6 +161,7 @@
62DC8D661AAA42700095DFA7 /* Rules */ = {
isa = PBXGroup;
children = (
623F29931AD836E6005B26CB /* MaxLengthRule.swift */,
628637251AAA474B00BC8FCF /* MinLengthRule.swift */,
62DC8D641AAA42520095DFA7 /* Rule.swift */,
62DC8D691AAA42CE0095DFA7 /* EmailRule.swift */,
@ -286,6 +289,7 @@
628637261AAA474B00BC8FCF /* MinLengthRule.swift in Sources */,
62DC8D711AAA43110095DFA7 /* ZipCodeRule.swift in Sources */,
62D1AE521A1E6FF800E4DFF8 /* ValidationRule.swift in Sources */,
623F29941AD836E6005B26CB /* MaxLengthRule.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -7,21 +7,21 @@
import Foundation
class MaxLengthRule: Rule {
public class MaxLengthRule: Rule {
private var DEFAULT_MAX_LENGTH: Int = 16
init(){}
public init(){}
init(length: Int){
public init(length: Int){
self.DEFAULT_MAX_LENGTH = length
}
func validate(value: String) -> Bool {
public func validate(value: String) -> Bool {
return countElements(value) <= DEFAULT_MAX_LENGTH
}
func errorMessage() -> String {
public func errorMessage() -> String {
return "Must be at most \(DEFAULT_MAX_LENGTH) characters long"
}
}