Skip to content

Commit 2018508

Browse files
committed
Swift 3 support for Xcode 8 + all tests
1 parent 6e856a9 commit 2018508

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+781
-751
lines changed

EZSwiftExtensions.xcodeproj/project.pbxproj

+16-1
Original file line numberDiff line numberDiff line change
@@ -596,14 +596,16 @@
596596
isa = PBXProject;
597597
attributes = {
598598
LastSwiftUpdateCheck = 0730;
599-
LastUpgradeCheck = 0710;
599+
LastUpgradeCheck = 0800;
600600
ORGANIZATIONNAME = "Goktug Yilmaz";
601601
TargetAttributes = {
602602
B5DC86A81C0ED06700972D0A = {
603603
CreatedOnToolsVersion = 7.1;
604+
LastSwiftMigration = 0800;
604605
};
605606
B5DC86B21C0ED06700972D0A = {
606607
CreatedOnToolsVersion = 7.1;
608+
LastSwiftMigration = 0800;
607609
};
608610
};
609611
};
@@ -933,8 +935,10 @@
933935
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
934936
CLANG_WARN_EMPTY_BODY = YES;
935937
CLANG_WARN_ENUM_CONVERSION = YES;
938+
CLANG_WARN_INFINITE_RECURSION = YES;
936939
CLANG_WARN_INT_CONVERSION = YES;
937940
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
941+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
938942
CLANG_WARN_UNREACHABLE_CODE = YES;
939943
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
940944
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -979,8 +983,10 @@
979983
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
980984
CLANG_WARN_EMPTY_BODY = YES;
981985
CLANG_WARN_ENUM_CONVERSION = YES;
986+
CLANG_WARN_INFINITE_RECURSION = YES;
982987
CLANG_WARN_INT_CONVERSION = YES;
983988
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
989+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
984990
CLANG_WARN_UNREACHABLE_CODE = YES;
985991
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
986992
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -999,6 +1005,7 @@
9991005
GCC_WARN_UNUSED_VARIABLE = YES;
10001006
MTL_ENABLE_DEBUG_INFO = NO;
10011007
SDKROOT = iphoneos;
1008+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
10021009
VALIDATE_PRODUCT = YES;
10031010
VERSIONING_SYSTEM = "apple-generic";
10041011
VERSION_INFO_PREFIX = "";
@@ -1008,6 +1015,7 @@
10081015
B5DC86BE1C0ED06700972D0A /* Debug */ = {
10091016
isa = XCBuildConfiguration;
10101017
buildSettings = {
1018+
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
10111019
DEFINES_MODULE = YES;
10121020
DYLIB_COMPATIBILITY_VERSION = 1;
10131021
DYLIB_CURRENT_VERSION = 1.0.2;
@@ -1019,13 +1027,15 @@
10191027
PRODUCT_BUNDLE_IDENTIFIER = com.gbf.EZSwiftExtensions.EZSwiftExtensions;
10201028
PRODUCT_NAME = EZSwiftExtensions;
10211029
SKIP_INSTALL = YES;
1030+
SWIFT_VERSION = 3.0;
10221031
TARGETED_DEVICE_FAMILY = "1,2";
10231032
};
10241033
name = Debug;
10251034
};
10261035
B5DC86BF1C0ED06700972D0A /* Release */ = {
10271036
isa = XCBuildConfiguration;
10281037
buildSettings = {
1038+
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
10291039
DEFINES_MODULE = YES;
10301040
DYLIB_COMPATIBILITY_VERSION = 1;
10311041
DYLIB_CURRENT_VERSION = 1.0.2;
@@ -1037,6 +1047,7 @@
10371047
PRODUCT_BUNDLE_IDENTIFIER = com.gbf.EZSwiftExtensions.EZSwiftExtensions;
10381048
PRODUCT_NAME = EZSwiftExtensions;
10391049
SKIP_INSTALL = YES;
1050+
SWIFT_VERSION = 3.0;
10401051
TARGETED_DEVICE_FAMILY = "1,2";
10411052
};
10421053
name = Release;
@@ -1048,6 +1059,7 @@
10481059
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
10491060
PRODUCT_BUNDLE_IDENTIFIER = com.gbf.EZSwiftExtensions.EZSwiftExtensionsTests;
10501061
PRODUCT_NAME = EZSwiftExtensionsTest;
1062+
SWIFT_VERSION = 3.0;
10511063
};
10521064
name = Debug;
10531065
};
@@ -1058,12 +1070,14 @@
10581070
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
10591071
PRODUCT_BUNDLE_IDENTIFIER = com.gbf.EZSwiftExtensions.EZSwiftExtensionsTests;
10601072
PRODUCT_NAME = EZSwiftExtensionsTest;
1073+
SWIFT_VERSION = 3.0;
10611074
};
10621075
name = Release;
10631076
};
10641077
CD4D30E11CEEAFD900CB53BC /* Debug */ = {
10651078
isa = XCBuildConfiguration;
10661079
buildSettings = {
1080+
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "";
10671081
DEFINES_MODULE = YES;
10681082
DYLIB_COMPATIBILITY_VERSION = 1;
10691083
DYLIB_CURRENT_VERSION = 1.0.2;
@@ -1082,6 +1096,7 @@
10821096
CD4D30E21CEEAFD900CB53BC /* Release */ = {
10831097
isa = XCBuildConfiguration;
10841098
buildSettings = {
1099+
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "";
10851100
DEFINES_MODULE = YES;
10861101
DYLIB_COMPATIBILITY_VERSION = 1;
10871102
DYLIB_CURRENT_VERSION = 1.0.2;

EZSwiftExtensions.xcodeproj/xcshareddata/xcschemes/EZSwiftExtensions-iOS.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0710"
3+
LastUpgradeVersion = "0800"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

EZSwiftExtensionsTests/ArrayTests.swift

+6-5
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,14 @@ class ArrayTests: XCTestCase {
126126
XCTAssertEqual(difference, [0, 5, 6, 7, 8])
127127
}
128128

129+
/// WARNING: [SE-0121] Remove Optional Comparison Operators
129130
func testOptionalEquatable() {
130131
let a: [Int]? = [1, 2, 3]
131132
let b: [Int]? = [1, 2, 3]
132-
let c: [Int]? = nil
133+
// let c: [Int]? = nil
133134

134-
XCTAssertTrue(a == b)
135-
XCTAssertFalse(a == c)
135+
XCTAssertTrue(a! == b!)
136+
// XCTAssertFalse(a! == c!)
136137
}
137138

138139
func testShuffle() {
@@ -144,8 +145,8 @@ class ArrayTests: XCTestCase {
144145
XCTAssertEqual(numberArray.count, copyArray.count)
145146

146147
for e in copyArray {
147-
if let i = numberArray.indexOf(e) {
148-
numberArray.removeAtIndex(i)
148+
if let i = numberArray.index(of: e) {
149+
numberArray.remove(at: i)
149150
}
150151
}
151152
XCTAssertEqual(numberArray, [])

EZSwiftExtensionsTests/DictionaryTests.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ class DictionaryTests: XCTestCase {
5959

6060
func testToArray() {
6161
let array = fourthDic.toArray { key, value in
62-
return key.uppercaseString + String(value)
62+
return key.uppercased() + String(value)
6363
}
6464

65-
XCTAssertNotNil(array.indexOf("TWO2"))
66-
XCTAssertNotNil(array.indexOf("FIVE5"))
65+
XCTAssertNotNil(array.index(of: "TWO2"))
66+
XCTAssertNotNil(array.index(of: "FIVE5"))
6767
XCTAssertEqual(array.count, fourthDic.count)
6868
}
6969

@@ -90,7 +90,7 @@ class DictionaryTests: XCTestCase {
9090
}
9191

9292
func testJSON () {
93-
let jsonDic = NSDictionary(dictionary: ["name": "John", "surname": "Smith", "age": 35.0, "married": NSNumber.init(bool: true), "children": 3])
93+
let jsonDic = NSDictionary(dictionary: ["name": "John", "surname": "Smith", "age": 35.0, "married": NSNumber.init(value: true as Bool), "children": 3])
9494
let jsonString = jsonDic.formatJSON()
9595
XCTAssertNotNil(jsonString)
9696
let secondJsonDic = NSDictionary(json: jsonString!)

EZSwiftExtensionsTests/EZSwiftFunctionsTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class EZSwiftFunctionsTests: XCTestCase {
2020
}
2121
var totalValue = 0
2222
var totalLoopCount = 0
23-
for e in ez.iterateEnum(testEnum) {
23+
for e in ez.iterateEnum(testEnum.self) {
2424
totalValue += e.rawValue
2525
totalLoopCount += 1
2626
}

EZSwiftExtensionsTests/ExampleTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class EZSwiftExtensionsTests: XCTestCase {
2828

2929
func testPerformanceExample() {
3030
// This is an example of a performance test case.
31-
self.measureBlock {
31+
self.measure {
3232
// Put the code you want to measure the time of here.
3333
}
3434
}

EZSwiftExtensionsTests/NSDateTests.swift

+24-13
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77
//
88

99
import XCTest
10+
fileprivate func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
11+
switch (lhs, rhs) {
12+
case let (l?, r?):
13+
return l < r
14+
case (nil, _?):
15+
return true
16+
default:
17+
return false
18+
}
19+
}
20+
1021

1122
class NSDateTests: XCTestCase {
1223
// note that NSDate uses UTC in NSDate(timeIntervalSince1970: _)
@@ -22,37 +33,37 @@ class NSDateTests: XCTestCase {
2233
}
2334

2435
func testDateFromString() {
25-
guard let dateFromString = NSDate(fromString: string, format: format) else {
36+
guard let dateFromString = Date(fromString: string, format: format) else {
2637
XCTFail("Date From String Couldn't be initialized.")
2738
return
2839
}
29-
let formatter = NSDateFormatter()
40+
let formatter = DateFormatter()
3041
formatter.dateFormat = format
31-
let dateString = formatter.dateFromString(string)
42+
let dateString = formatter.date(from: string)
3243
XCTAssertEqual(dateFromString, dateString)
33-
XCTAssertNil(NSDate(fromString: wrongDateString, format: format), "Date From String initialized, but source string was invalid.")
44+
XCTAssertNil(Date(fromString: wrongDateString, format: format), "Date From String initialized, but source string was invalid.")
3445
}
3546

3647
func testDateToString() {
37-
let date = NSDate(timeIntervalSince1970: 0)
48+
let date = Date(timeIntervalSince1970: 0)
3849

39-
let formatter = NSDateFormatter()
50+
let formatter = DateFormatter()
4051
formatter.dateFormat = format
41-
let dateString = formatter.stringFromDate(date)
52+
let dateString = formatter.string(from: date)
4253

4354
XCTAssertEqual(date.toString(format: format), dateString)
4455
}
4556

4657
func testTimePassedBetweenDates() {
47-
let date = NSDate(timeIntervalSince1970: 0)
48-
XCTAssertTrue(date.timePassed().containsString("years"))
49-
let now = NSDate()
50-
XCTAssertTrue(now.timePassed().containsString("now") || now.timePassed().containsString("seconds"))
58+
let date = Date(timeIntervalSince1970: 0)
59+
XCTAssertTrue(date.timePassed().contains("years"))
60+
let now = Date()
61+
XCTAssertTrue(now.timePassed().contains("now") || now.timePassed().contains("seconds"))
5162
}
5263

5364
func testComparable() {
54-
let date = NSDate()
55-
let future = NSDate(timeIntervalSinceNow: 1000)
65+
let date = Date()
66+
let future = Date(timeIntervalSinceNow: 1000)
5667
XCTAssertTrue(date < future)
5768
XCTAssertFalse(date > future)
5869
XCTAssertTrue(date == date)

EZSwiftExtensionsTests/NSURLTests.swift

+11-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import XCTest
1111

1212
class NSURLTests: XCTestCase {
1313
func testQueryParameters() {
14-
let url = NSURL(string: "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=facebook")
14+
let url = URL(string: "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=facebook")
1515
if let queryParameters = url?.queryParameters {
1616
XCTAssertEqual(queryParameters["v"], Optional("1.0"))
1717
XCTAssertEqual(queryParameters["q"], Optional("facebook"))
@@ -22,27 +22,27 @@ class NSURLTests: XCTestCase {
2222
func testRemote() {
2323
var len: Int64?
2424
var support: Bool?
25-
let urlResume = NSURL(string: "http://httpbin.org/range/1024")!
26-
let urlSize = NSURL(string: "http://httpbin.org/bytes/1024")!
27-
let group = dispatch_group_create()
28-
dispatch_group_enter(group)
25+
let urlResume = URL(string: "http://httpbin.org/range/1024")!
26+
let urlSize = URL(string: "http://httpbin.org/bytes/1024")!
27+
let group = DispatchGroup()
28+
group.enter()
2929
urlSize.remoteSize({ (contentLength: Int64) in
3030
len = contentLength
31-
dispatch_group_leave(group)
31+
group.leave()
3232
})
33-
dispatch_group_enter(group)
33+
group.enter()
3434
urlResume.supportsResume({ (doesSupport: Bool) in
3535
support = doesSupport
36-
dispatch_group_leave(group)
36+
group.leave()
3737
})
38-
dispatch_group_wait(group, dispatch_time(DISPATCH_TIME_NOW, Int64(30 * NSEC_PER_SEC)))
38+
_ = group.wait(timeout: DispatchTime.now() + Double(Int64(30 * NSEC_PER_SEC)) / Double(NSEC_PER_SEC))
3939
XCTAssertEqual(len, 1024)
4040
XCTAssertEqual(support, true)
4141
}
4242

4343
func testIsSame() {
44-
let url1 = NSURL(string: "http://google.com/")!
45-
let url2 = NSURL(string: "http://www.google.com")!
44+
let url1 = URL(string: "http://google.com/")!
45+
let url2 = URL(string: "http://www.google.com")!
4646
XCTAssertTrue(url1.isSameWithURL(url2))
4747
}
4848

EZSwiftExtensionsTests/StringTests.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class StringTests: XCTestCase {
2020
func testSubscript() {
2121
XCTAssertEqual(string[2], "2")
2222
XCTAssertEqual(string[9], "9")
23-
XCTAssertEqual(string[0...9], "0123456789")
23+
XCTAssertEqual(string[0..<10], "0123456789")
2424
XCTAssertEqual(string[3..<5], "34")
2525
}
2626

@@ -146,8 +146,8 @@ class StringTests: XCTestCase {
146146

147147
func testContains() {
148148
XCTAssertTrue(string.contains("01"))
149-
XCTAssertTrue(string.contains("01", compareOption: NSStringCompareOptions.AnchoredSearch))
150-
XCTAssertFalse(string.contains("12", compareOption: NSStringCompareOptions.AnchoredSearch))
149+
XCTAssertTrue(string.contains("01", compareOption: NSString.CompareOptions.anchored))
150+
XCTAssertFalse(string.contains("12", compareOption: NSString.CompareOptions.anchored))
151151
XCTAssertFalse(string.contains("h"))
152152
}
153153

@@ -158,7 +158,7 @@ class StringTests: XCTestCase {
158158
XCTAssertNotNil(string.toFloat())
159159
XCTAssertEqual(String(10.253, precision: 2), "10.25")
160160
XCTAssertEqual(String(10.257, precision: 2), "10.26")
161-
XCTAssertTrue(string.toNSString.isKindOfClass(NSString.self))
161+
XCTAssertTrue(string.toNSString.isKind(of: NSString.self))
162162
}
163163

164164
func testIsIncludeEmoji() {

0 commit comments

Comments
 (0)