Skip to content

Commit 87ec25c

Browse files
committed
Update for Xcode 8 and Swift 3
1 parent 0e81e07 commit 87ec25c

File tree

4 files changed

+31
-19
lines changed

4 files changed

+31
-19
lines changed

Prime Numbers/Primes/Primes.xcodeproj/project.pbxproj

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,18 +191,21 @@
191191
isa = PBXProject;
192192
attributes = {
193193
LastSwiftUpdateCheck = 0730;
194-
LastUpgradeCheck = 0730;
194+
LastUpgradeCheck = 0800;
195195
ORGANIZATIONNAME = "Pratikbhai Patel";
196196
TargetAttributes = {
197197
31900F3F1D0EF73700F8673F = {
198198
CreatedOnToolsVersion = 7.3.1;
199+
LastSwiftMigration = 0800;
199200
};
200201
31900F531D0EF73700F8673F = {
201202
CreatedOnToolsVersion = 7.3.1;
203+
LastSwiftMigration = 0800;
202204
TestTargetID = 31900F3F1D0EF73700F8673F;
203205
};
204206
31900F5E1D0EF73700F8673F = {
205207
CreatedOnToolsVersion = 7.3.1;
208+
LastSwiftMigration = 0800;
206209
TestTargetID = 31900F3F1D0EF73700F8673F;
207210
};
208211
};
@@ -409,6 +412,7 @@
409412
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
410413
PRODUCT_BUNDLE_IDENTIFIER = com.pratikpatel.Primes;
411414
PRODUCT_NAME = "$(TARGET_NAME)";
415+
SWIFT_VERSION = 3.0;
412416
};
413417
name = Debug;
414418
};
@@ -420,6 +424,8 @@
420424
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
421425
PRODUCT_BUNDLE_IDENTIFIER = com.pratikpatel.Primes;
422426
PRODUCT_NAME = "$(TARGET_NAME)";
427+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
428+
SWIFT_VERSION = 3.0;
423429
};
424430
name = Release;
425431
};
@@ -431,6 +437,7 @@
431437
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
432438
PRODUCT_BUNDLE_IDENTIFIER = com.pratikpatel.PrimesTests;
433439
PRODUCT_NAME = "$(TARGET_NAME)";
440+
SWIFT_VERSION = 3.0;
434441
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Primes.app/Primes";
435442
};
436443
name = Debug;
@@ -443,6 +450,8 @@
443450
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
444451
PRODUCT_BUNDLE_IDENTIFIER = com.pratikpatel.PrimesTests;
445452
PRODUCT_NAME = "$(TARGET_NAME)";
453+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
454+
SWIFT_VERSION = 3.0;
446455
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Primes.app/Primes";
447456
};
448457
name = Release;
@@ -454,6 +463,7 @@
454463
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
455464
PRODUCT_BUNDLE_IDENTIFIER = com.pratikpatel.PrimesUITests;
456465
PRODUCT_NAME = "$(TARGET_NAME)";
466+
SWIFT_VERSION = 3.0;
457467
TEST_TARGET_NAME = Primes;
458468
};
459469
name = Debug;
@@ -465,6 +475,8 @@
465475
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
466476
PRODUCT_BUNDLE_IDENTIFIER = com.pratikpatel.PrimesUITests;
467477
PRODUCT_NAME = "$(TARGET_NAME)";
478+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
479+
SWIFT_VERSION = 3.0;
468480
TEST_TARGET_NAME = Primes;
469481
};
470482
name = Release;

Prime Numbers/Primes/Primes/AppDelegate.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1313

1414
var window: UIWindow?
1515

16-
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
16+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
1717
// Override point for customization after application launch.
1818
performPrimesGeneration()
1919
return true
@@ -25,15 +25,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2525

2626
let primeGenerator = PrimeGenerator.sharedInstance
2727

28-
var startDate = NSDate().timeIntervalSince1970 * 1000
28+
var startDate = Date()
2929
let era_sieve = primeGenerator.eratosthenesPrimes(primesTo)
30-
var endDate = NSDate().timeIntervalSince1970 * 1000
31-
print("Prime generation time for sieve of eratosthenes: \(endDate - startDate) ms.")
30+
var endDate = Date()
31+
print("Prime generation time for sieve of eratosthenes: \(endDate.timeIntervalSince(startDate) * 1000) ms.")
3232

33-
startDate = NSDate().timeIntervalSince1970 * 1000
33+
startDate = Date()
3434
let at_sieve = primeGenerator.atkinsPrimes(primesTo)
35-
endDate = NSDate().timeIntervalSince1970 * 1000
36-
print("Prime generation time for atkins sieve: \(endDate - startDate) ms.")
35+
endDate = Date()
36+
print("Prime generation time for atkins sieve: \(endDate.timeIntervalSince(startDate) * 1000) ms.")
3737
print("they are equal \(era_sieve == at_sieve)")
3838
}
3939

Prime Numbers/Primes/Primes/PrimeGenerator.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,29 @@ func ..<T: Strideable>(left: T, right: T.Stride) -> (T, T.Stride) {
2020
}
2121

2222
func ..<T: Strideable>(left: (T, T.Stride), right: T) -> [T] {
23-
return [T](left.0.stride(through: right, by: left.1))
23+
return [T](stride(from: left.0, through: right, by: left.1))
2424
}
2525

2626
class PrimeGenerator {
2727

2828
static let sharedInstance = PrimeGenerator()
2929

30-
func eratosthenesPrimes(max: Int) -> [Int] {
30+
func eratosthenesPrimes(_ max: Int) -> [Int] {
3131
let m = Int(sqrt(ceil(Double(max))))
3232
let set = NSMutableSet(array: 3..2..max)
33-
set.addObject(2)
33+
set.add(2)
3434
for i in (2..1..m) {
35-
if (set.containsObject(i)) {
35+
if (set.contains(i)) {
3636
for j in i^^2..i..max {
37-
set.removeObject(j)
37+
set.remove(j)
3838
}
3939
}
4040
}
41-
return set.sortedArrayUsingDescriptors([NSSortDescriptor(key: "integerValue", ascending: true)]) as! [Int]
41+
return set.sortedArray(using: [SortDescriptor(key: "integerValue", ascending: true)]) as! [Int]
4242
}
4343

44-
func atkinsPrimes(max: Int) -> [Int] {
45-
var is_prime = [Bool](count: max + 1, repeatedValue: false)
44+
func atkinsPrimes(_ max: Int) -> [Int] {
45+
var is_prime = [Bool](repeating: false, count: max + 1)
4646
is_prime[2] = true
4747
is_prime[3] = true
4848
let limit = Int(ceil(sqrt(Double(max))))
@@ -74,10 +74,10 @@ class PrimeGenerator {
7474
}
7575
}
7676
var primesArray = [Int]()
77-
for (idx, val) in is_prime.enumerate() {
77+
for (idx, val) in is_prime.enumerated() {
7878
if val == true { primesArray.append(idx) }
7979
}
8080
return primesArray
8181
}
8282

83-
}
83+
}

Prime Numbers/Primes/PrimesTests/PrimesTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class PrimesTests: 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
}

0 commit comments

Comments
 (0)