Skip to content

Commit d801538

Browse files
committed
Merge pull request #52 from goodeggs/swift-2.0
Migrate to Swift 2.0
2 parents ca65096 + 45da08a commit d801538

13 files changed

+39
-37
lines changed

SwiftValidator.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "SwiftValidator"
3-
s.version = "2.1.1"
3+
s.version = "3.0.0"
44
s.summary = "A UITextField Validation library for Swift"
55
s.homepage = "https://github.com/jpotts18/SwiftValidator"
66
s.screenshots = "https://raw.githubusercontent.com/jpotts18/SwiftValidator/master/swift-validator-v2.gif"
@@ -9,7 +9,7 @@ Pod::Spec.new do |s|
99
s.social_media_url = "http://twitter.com/jpotts18"
1010
s.platform = :ios
1111
s.ios.deployment_target = '8.0'
12-
s.source = { :git => "https://github.com/jpotts18/SwiftValidator.git", :tag => "2.1.1" }
12+
s.source = { :git => "https://github.com/jpotts18/SwiftValidator.git", :tag => "3.0.0" }
1313
s.source_files = "Validator/*.swift"
1414
s.frameworks = ['Foundation', 'UIKit']
1515
s.requires_arc = true

Validator.xcodeproj/project.pbxproj

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
62DC8D6E1AAA42CE0095DFA7 /* PasswordRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62DC8D6B1AAA42CE0095DFA7 /* PasswordRule.swift */; };
2727
62DC8D711AAA43110095DFA7 /* ZipCodeRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62DC8D701AAA43110095DFA7 /* ZipCodeRule.swift */; };
2828
62E9E2AD1ACFB336000A939C /* RegexRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62E9E2AC1ACFB336000A939C /* RegexRule.swift */; };
29+
D7C1D97E1BA25940008CE686 /* PhoneNumberRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7C1D97D1BA25940008CE686 /* PhoneNumberRule.swift */; settings = {ASSET_TAGS = (); }; };
2930
DC5A35EC1AF99BA60013FE6B /* FloatRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC5A35EB1AF99BA60013FE6B /* FloatRule.swift */; };
3031
/* End PBXBuildFile section */
3132

@@ -63,6 +64,7 @@
6364
62DC8D6B1AAA42CE0095DFA7 /* PasswordRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasswordRule.swift; sourceTree = "<group>"; };
6465
62DC8D701AAA43110095DFA7 /* ZipCodeRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ZipCodeRule.swift; sourceTree = "<group>"; };
6566
62E9E2AC1ACFB336000A939C /* RegexRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RegexRule.swift; sourceTree = "<group>"; };
67+
D7C1D97D1BA25940008CE686 /* PhoneNumberRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhoneNumberRule.swift; sourceTree = "<group>"; };
6668
DC5A35EB1AF99BA60013FE6B /* FloatRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FloatRule.swift; sourceTree = "<group>"; };
6769
/* End PBXFileReference section */
6870

@@ -163,17 +165,18 @@
163165
62DC8D661AAA42700095DFA7 /* Rules */ = {
164166
isa = PBXGroup;
165167
children = (
168+
628637271AAA49E300BC8FCF /* ConfirmRule.swift */,
169+
62DC8D691AAA42CE0095DFA7 /* EmailRule.swift */,
170+
DC5A35EB1AF99BA60013FE6B /* FloatRule.swift */,
171+
62DC8D671AAA42920095DFA7 /* FullNameRule.swift */,
166172
623F29931AD836E6005B26CB /* MaxLengthRule.swift */,
167173
628637251AAA474B00BC8FCF /* MinLengthRule.swift */,
168-
62DC8D641AAA42520095DFA7 /* Rule.swift */,
169-
62DC8D691AAA42CE0095DFA7 /* EmailRule.swift */,
170-
62DC8D6A1AAA42CE0095DFA7 /* RequiredRule.swift */,
171174
62DC8D6B1AAA42CE0095DFA7 /* PasswordRule.swift */,
172-
62DC8D671AAA42920095DFA7 /* FullNameRule.swift */,
173-
62DC8D701AAA43110095DFA7 /* ZipCodeRule.swift */,
174-
628637271AAA49E300BC8FCF /* ConfirmRule.swift */,
175+
D7C1D97D1BA25940008CE686 /* PhoneNumberRule.swift */,
175176
62E9E2AC1ACFB336000A939C /* RegexRule.swift */,
176-
DC5A35EB1AF99BA60013FE6B /* FloatRule.swift */,
177+
62DC8D6A1AAA42CE0095DFA7 /* RequiredRule.swift */,
178+
62DC8D641AAA42520095DFA7 /* Rule.swift */,
179+
62DC8D701AAA43110095DFA7 /* ZipCodeRule.swift */,
177180
);
178181
name = Rules;
179182
sourceTree = "<group>";
@@ -222,7 +225,8 @@
222225
62D1AE0F1A1E6D4400E4DFF8 /* Project object */ = {
223226
isa = PBXProject;
224227
attributes = {
225-
LastUpgradeCheck = 0610;
228+
LastSwiftMigration = 0700;
229+
LastUpgradeCheck = 0700;
226230
ORGANIZATIONNAME = jpotts18;
227231
TargetAttributes = {
228232
62D1AE161A1E6D4400E4DFF8 = {
@@ -283,6 +287,7 @@
283287
62D1AE4F1A1E6FF800E4DFF8 /* ValidationError.swift in Sources */,
284288
62DC8D6E1AAA42CE0095DFA7 /* PasswordRule.swift in Sources */,
285289
62DC8D6C1AAA42CE0095DFA7 /* EmailRule.swift in Sources */,
290+
D7C1D97E1BA25940008CE686 /* PhoneNumberRule.swift in Sources */,
286291
628637281AAA49E300BC8FCF /* ConfirmRule.swift in Sources */,
287292
62DC8D651AAA42520095DFA7 /* Rule.swift in Sources */,
288293
62D1AE1F1A1E6D4400E4DFF8 /* ViewController.swift in Sources */,
@@ -355,6 +360,7 @@
355360
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
356361
COPY_PHASE_STRIP = NO;
357362
ENABLE_STRICT_OBJC_MSGSEND = YES;
363+
ENABLE_TESTABILITY = YES;
358364
GCC_C_LANGUAGE_STANDARD = gnu99;
359365
GCC_DYNAMIC_NO_PIC = NO;
360366
GCC_OPTIMIZATION_LEVEL = 0;
@@ -418,6 +424,7 @@
418424
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
419425
INFOPLIST_FILE = Validator/Info.plist;
420426
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
427+
PRODUCT_BUNDLE_IDENTIFIER = "me.jeffpotter.$(PRODUCT_NAME:rfc1034identifier)";
421428
PRODUCT_NAME = "$(TARGET_NAME)";
422429
};
423430
name = Debug;
@@ -428,6 +435,7 @@
428435
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
429436
INFOPLIST_FILE = Validator/Info.plist;
430437
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
438+
PRODUCT_BUNDLE_IDENTIFIER = "me.jeffpotter.$(PRODUCT_NAME:rfc1034identifier)";
431439
PRODUCT_NAME = "$(TARGET_NAME)";
432440
};
433441
name = Release;
@@ -436,16 +444,13 @@
436444
isa = XCBuildConfiguration;
437445
buildSettings = {
438446
BUNDLE_LOADER = "$(TEST_HOST)";
439-
FRAMEWORK_SEARCH_PATHS = (
440-
"$(SDKROOT)/Developer/Library/Frameworks",
441-
"$(inherited)",
442-
);
443447
GCC_PREPROCESSOR_DEFINITIONS = (
444448
"DEBUG=1",
445449
"$(inherited)",
446450
);
447451
INFOPLIST_FILE = ValidatorTests/Info.plist;
448452
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
453+
PRODUCT_BUNDLE_IDENTIFIER = "me.jeffpotter.$(PRODUCT_NAME:rfc1034identifier)";
449454
PRODUCT_NAME = "$(TARGET_NAME)";
450455
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Validator.app/Validator";
451456
};
@@ -455,12 +460,9 @@
455460
isa = XCBuildConfiguration;
456461
buildSettings = {
457462
BUNDLE_LOADER = "$(TEST_HOST)";
458-
FRAMEWORK_SEARCH_PATHS = (
459-
"$(SDKROOT)/Developer/Library/Frameworks",
460-
"$(inherited)",
461-
);
462463
INFOPLIST_FILE = ValidatorTests/Info.plist;
463464
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
465+
PRODUCT_BUNDLE_IDENTIFIER = "me.jeffpotter.$(PRODUCT_NAME:rfc1034identifier)";
464466
PRODUCT_NAME = "$(TARGET_NAME)";
465467
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Validator.app/Validator";
466468
};

Validator/FloatRule.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ public class FloatRule:Rule {
1717
}
1818

1919
public func validate(value: String) -> Bool {
20-
let regex = NSRegularExpression(pattern: "[-+]?(\\d*[.])?\\d+", options: nil, error: nil)
20+
let regex = try? NSRegularExpression(pattern: "[-+]?(\\d*[.])?\\d+", options: [])
2121
if let regex = regex {
22-
let match = regex.numberOfMatchesInString(value, options: nil, range: NSRange(location: 0, length: count(value)))
22+
let match = regex.numberOfMatchesInString(value, options: [], range: NSRange(location: 0, length: value.characters.count))
2323
return match == 1
2424
}
2525
return false

Validator/FullNameRule.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class FullNameRule : Rule {
1818
}
1919

2020
public func validate(value: String) -> Bool {
21-
var nameArray: [String] = split(value) { $0 == " " }
21+
let nameArray: [String] = value.characters.split { $0 == " " }.map { String($0) }
2222
return nameArray.count >= 2
2323
}
2424

Validator/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<key>CFBundleExecutable</key>
88
<string>$(EXECUTABLE_NAME)</string>
99
<key>CFBundleIdentifier</key>
10-
<string>me.jeffpotter.$(PRODUCT_NAME:rfc1034identifier)</string>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
1111
<key>CFBundleInfoDictionaryVersion</key>
1212
<string>6.0</string>
1313
<key>CFBundleName</key>

Validator/MaxLengthRule.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class MaxLengthRule: Rule {
2020
}
2121

2222
public func validate(value: String) -> Bool {
23-
return count(value) <= DEFAULT_LENGTH
23+
return value.characters.count <= DEFAULT_LENGTH
2424
}
2525

2626
public func errorMessage() -> String {

Validator/MinLengthRule.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class MinLengthRule: Rule {
2121
}
2222

2323
public func validate(value: String) -> Bool {
24-
return count(value) >= DEFAULT_LENGTH
24+
return value.characters.count >= DEFAULT_LENGTH
2525
}
2626

2727
public func errorMessage() -> String {

Validator/PhoneNumberRule.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class PhoneNumberRule: Rule {
1717
}
1818

1919
func validate(value: String) -> Bool {
20-
var phoneTest = NSPredicate(format: "SELF MATCHES %@", PHONE_REGEX)
20+
let phoneTest = NSPredicate(format: "SELF MATCHES %@", PHONE_REGEX)
2121
return phoneTest.evaluateWithObject(value)
2222
}
2323

Validator/ValidationError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Foundation
1010
import UIKit
1111

12-
public class ValidationError {
12+
public class ValidationError: NSObject {
1313
public let textField:UITextField
1414
public var errorLabel:UILabel?
1515
public let errorMessage:String

Validator/ValidationRule.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class ValidationRule {
2121
}
2222

2323
public func validateField() -> ValidationError? {
24-
return rules.filter{ !$0.validate(self.textField.text) }
24+
return rules.filter{ !$0.validate(self.textField.text ?? "") }
2525
.map{ rule -> ValidationError in return ValidationError(textField: self.textField, errorLabel:self.errorLabel, error: rule.errorMessage()) }.first
2626
}
2727
}

0 commit comments

Comments
 (0)