Skip to content
This repository was archived by the owner on Feb 8, 2023. It is now read-only.

Commit 6e70235

Browse files
authored
Merge pull request #32 from mac-cain13/swift3
Swift 3 conversion
2 parents c0fb4cb + 91d206b commit 6e70235

25 files changed

+462
-368
lines changed

CoreDataKit.xcodeproj/project.pbxproj

+20-5
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@
300300
attributes = {
301301
LastSwiftMigration = 0700;
302302
LastSwiftUpdateCheck = 0700;
303-
LastUpgradeCheck = 0700;
303+
LastUpgradeCheck = 0800;
304304
ORGANIZATIONNAME = "Mathijs Kadijk";
305305
TargetAttributes = {
306306
D5D7C6BB1958B8CF0048B576 = {
@@ -309,7 +309,9 @@
309309
};
310310
D5D7C6C61958B8CF0048B576 = {
311311
CreatedOnToolsVersion = 6.0;
312+
DevelopmentTeam = LC3Y92HQQ3;
312313
LastSwiftMigration = 0800;
314+
ProvisioningStyle = Automatic;
313315
TestTargetID = D5D7C6BB1958B8CF0048B576;
314316
};
315317
};
@@ -429,8 +431,10 @@
429431
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
430432
CLANG_WARN_EMPTY_BODY = YES;
431433
CLANG_WARN_ENUM_CONVERSION = YES;
434+
CLANG_WARN_INFINITE_RECURSION = YES;
432435
CLANG_WARN_INT_CONVERSION = YES;
433436
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
437+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
434438
CLANG_WARN_UNREACHABLE_CODE = YES;
435439
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
436440
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -440,6 +444,7 @@
440444
ENABLE_TESTABILITY = YES;
441445
GCC_C_LANGUAGE_STANDARD = gnu99;
442446
GCC_DYNAMIC_NO_PIC = NO;
447+
GCC_NO_COMMON_BLOCKS = YES;
443448
GCC_OPTIMIZATION_LEVEL = 0;
444449
GCC_PREPROCESSOR_DEFINITIONS = (
445450
"DEBUG=1",
@@ -476,8 +481,10 @@
476481
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
477482
CLANG_WARN_EMPTY_BODY = YES;
478483
CLANG_WARN_ENUM_CONVERSION = YES;
484+
CLANG_WARN_INFINITE_RECURSION = YES;
479485
CLANG_WARN_INT_CONVERSION = YES;
480486
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
487+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
481488
CLANG_WARN_UNREACHABLE_CODE = YES;
482489
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
483490
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -486,6 +493,7 @@
486493
ENABLE_NS_ASSERTIONS = NO;
487494
ENABLE_STRICT_OBJC_MSGSEND = YES;
488495
GCC_C_LANGUAGE_STANDARD = gnu99;
496+
GCC_NO_COMMON_BLOCKS = YES;
489497
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
490498
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
491499
GCC_WARN_UNDECLARED_SELECTOR = YES;
@@ -495,6 +503,7 @@
495503
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
496504
METAL_ENABLE_DEBUG_INFO = NO;
497505
SDKROOT = iphoneos;
506+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
498507
TARGETED_DEVICE_FAMILY = "1,2";
499508
VALIDATE_PRODUCT = YES;
500509
VERSIONING_SYSTEM = "apple-generic";
@@ -506,6 +515,7 @@
506515
isa = XCBuildConfiguration;
507516
buildSettings = {
508517
CLANG_ENABLE_MODULES = YES;
518+
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
509519
DEFINES_MODULE = YES;
510520
DYLIB_COMPATIBILITY_VERSION = 1;
511521
DYLIB_CURRENT_VERSION = 1;
@@ -518,14 +528,15 @@
518528
PRODUCT_NAME = "$(TARGET_NAME)";
519529
SKIP_INSTALL = YES;
520530
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
521-
SWIFT_VERSION = 2.3;
531+
SWIFT_VERSION = 3.0;
522532
};
523533
name = Debug;
524534
};
525535
D5D7C6D41958B8CF0048B576 /* Release */ = {
526536
isa = XCBuildConfiguration;
527537
buildSettings = {
528538
CLANG_ENABLE_MODULES = YES;
539+
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
529540
DEFINES_MODULE = YES;
530541
DYLIB_COMPATIBILITY_VERSION = 1;
531542
DYLIB_CURRENT_VERSION = 1;
@@ -537,13 +548,15 @@
537548
PRODUCT_BUNDLE_IDENTIFIER = "nl.mathijskadijk.${PRODUCT_NAME:rfc1034identifier}";
538549
PRODUCT_NAME = "$(TARGET_NAME)";
539550
SKIP_INSTALL = YES;
540-
SWIFT_VERSION = 2.3;
551+
SWIFT_VERSION = 3.0;
541552
};
542553
name = Release;
543554
};
544555
D5D7C6D61958B8CF0048B576 /* Debug */ = {
545556
isa = XCBuildConfiguration;
546557
buildSettings = {
558+
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
559+
DEVELOPMENT_TEAM = LC3Y92HQQ3;
547560
FRAMEWORK_SEARCH_PATHS = (
548561
"$(SDKROOT)/Developer/Library/Frameworks",
549562
"$(inherited)",
@@ -557,13 +570,15 @@
557570
METAL_ENABLE_DEBUG_INFO = YES;
558571
PRODUCT_BUNDLE_IDENTIFIER = "nl.mathijskadijk.${PRODUCT_NAME:rfc1034identifier}";
559572
PRODUCT_NAME = "$(TARGET_NAME)";
560-
SWIFT_VERSION = 2.3;
573+
SWIFT_VERSION = 3.0;
561574
};
562575
name = Debug;
563576
};
564577
D5D7C6D71958B8CF0048B576 /* Release */ = {
565578
isa = XCBuildConfiguration;
566579
buildSettings = {
580+
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
581+
DEVELOPMENT_TEAM = LC3Y92HQQ3;
567582
FRAMEWORK_SEARCH_PATHS = (
568583
"$(SDKROOT)/Developer/Library/Frameworks",
569584
"$(inherited)",
@@ -573,7 +588,7 @@
573588
METAL_ENABLE_DEBUG_INFO = NO;
574589
PRODUCT_BUNDLE_IDENTIFIER = "nl.mathijskadijk.${PRODUCT_NAME:rfc1034identifier}";
575590
PRODUCT_NAME = "$(TARGET_NAME)";
576-
SWIFT_VERSION = 2.3;
591+
SWIFT_VERSION = 3.0;
577592
};
578593
name = Release;
579594
};

CoreDataKit.xcodeproj/xcshareddata/xcschemes/CoreDataKit.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 = "0700"
3+
LastUpgradeVersion = "0800"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

CoreDataKit/CDK.swift

+21-11
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
import CoreData
1010

1111
public enum CDKLogLevel {
12-
case DEBUG
13-
case INFO
14-
case WARN
15-
case ERROR
12+
case debug
13+
case info
14+
case warn
15+
case error
1616
}
1717

1818
public typealias Logger = (CDKLogLevel, String) -> Void
@@ -22,7 +22,7 @@ public typealias Logger = (CDKLogLevel, String) -> Void
2222
*/
2323
public class CDK : NSObject
2424
{
25-
private struct Holder {
25+
fileprivate struct Holder {
2626
static var sharedStack: CoreDataStack?
2727
static var sharedLogger: Logger = { _, message in print("[CoreDataKit] \(message)") }
2828
}
@@ -34,7 +34,7 @@ public class CDK : NSObject
3434
*/
3535
public class var sharedStack: CoreDataStack? {
3636
get {
37-
return Holder.sharedStack
37+
return Holder.sharedStack
3838
}
3939

4040
set {
@@ -49,7 +49,7 @@ public class CDK : NSObject
4949
*/
5050
public class var sharedLogger: Logger {
5151
get {
52-
return Holder.sharedLogger
52+
return Holder.sharedLogger
5353
}
5454

5555
set {
@@ -82,11 +82,21 @@ public class CDK : NSObject
8282

8383
:see: NSManagedObjectContext.performBlock()
8484
*/
85-
public class func performBlockOnBackgroundContext(block: PerformBlock, completionHandler: PerformBlockCompletionHandler?) {
86-
sharedStack!.performBlockOnBackgroundContext(block, completionHandler: completionHandler)
85+
public class func performOnBackgroundContext(block: @escaping PerformBlock, completionHandler: PerformBlockCompletionHandler?) {
86+
sharedStack!.performOnBackgroundContext(block: block, completionHandler: completionHandler)
8787
}
8888

89-
public class func performBlockOnBackgroundContext(block: PerformBlock) {
90-
sharedStack!.performBlockOnBackgroundContext(block, completionHandler: nil)
89+
@available(*, unavailable, renamed: "performOnBackgroundContext(block:completionHandler:)")
90+
public class func performBlockOnBackgroundContext(_ block: PerformBlock, completionHandler: PerformBlockCompletionHandler?) {
91+
fatalError()
92+
}
93+
94+
public class func performOnBackgroundContext(block: @escaping PerformBlock) {
95+
sharedStack!.performOnBackgroundContext(block: block, completionHandler: nil)
96+
}
97+
98+
@available(*, unavailable, renamed: "performOnBackgroundContext(block:)")
99+
public class func performBlockOnBackgroundContext(_ block: PerformBlock) {
100+
fatalError()
91101
}
92102
}

CoreDataKit/CoreDataStack.swift

+20-10
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class CoreDataStack: NSObject {
3232
self.rootContext = NSManagedObjectContext(persistentStoreCoordinator: self.persistentStoreCoordinator)
3333
self.rootContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
3434

35-
self.mainThreadContext = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType, parentContext: rootContext)
35+
self.mainThreadContext = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType, parentContext: rootContext)
3636

3737
self.backgroundContext = self.mainThreadContext.createChildContext()
3838

@@ -56,23 +56,33 @@ public class CoreDataStack: NSObject {
5656

5757
:see: NSManagedObjectContext.performBlock()
5858
*/
59-
public func performBlockOnBackgroundContext(block: PerformBlock, completionHandler: PerformBlockCompletionHandler?) {
60-
backgroundContext.performBlock(block, completionHandler: completionHandler)
59+
public func performOnBackgroundContext(block: @escaping PerformBlock, completionHandler: PerformBlockCompletionHandler?) {
60+
backgroundContext.perform(block: block, completionHandler: completionHandler)
6161
}
6262

63-
public func performBlockOnBackgroundContext(block: PerformBlock) {
64-
backgroundContext.performBlock(block, completionHandler: nil)
63+
@available(*, unavailable, renamed: "performOnBackgroundContext(block:completionHandler:)")
64+
public func performBlockOnBackgroundContext(_ block: PerformBlock, completionHandler: PerformBlockCompletionHandler?) {
65+
fatalError()
66+
}
67+
68+
public func performOnBackgroundContext(block: @escaping PerformBlock) {
69+
backgroundContext.perform(block: block, completionHandler: nil)
70+
}
71+
72+
@available(*, unavailable, renamed: "performOnBackgroundContext(block:)")
73+
public func performBlockOnBackgroundContext(_ block: PerformBlock) {
74+
fatalError()
6575
}
6676

6777
/**
6878
Dumps some debug info about this stack to the console
6979
*/
7080
public func dumpStack() {
71-
CDK.sharedLogger(.DEBUG, "Stores: \(persistentStoreCoordinator.persistentStores)")
72-
CDK.sharedLogger(.DEBUG, " - Store coordinator: \(persistentStoreCoordinator.debugDescription)")
73-
CDK.sharedLogger(.DEBUG, " |- Root context: \(rootContext.debugDescription)")
74-
CDK.sharedLogger(.DEBUG, " |- Main thread context: \(mainThreadContext.debugDescription)")
75-
CDK.sharedLogger(.DEBUG, " |- Background context: \(backgroundContext.debugDescription)")
81+
CDK.sharedLogger(.debug, "Stores: \(persistentStoreCoordinator.persistentStores)")
82+
CDK.sharedLogger(.debug, " - Store coordinator: \(persistentStoreCoordinator.debugDescription)")
83+
CDK.sharedLogger(.debug, " |- Root context: \(rootContext.debugDescription)")
84+
CDK.sharedLogger(.debug, " |- Main thread context: \(mainThreadContext.debugDescription)")
85+
CDK.sharedLogger(.debug, " |- Background context: \(backgroundContext.debugDescription)")
7686
}
7787

7888
// MARK: Notification observers

CoreDataKit/Importing/CoreDataStack+Importing.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ extension CoreDataStack {
1616
let entityUserInfoKeys = [IdentifierUserInfoKey]
1717

1818
for (entityName, entity) in persistentStoreCoordinator.managedObjectModel.entitiesByName {
19-
CDK.sharedLogger(.DEBUG, " ")
20-
CDK.sharedLogger(.DEBUG, "\(entityName):")
19+
CDK.sharedLogger(.debug, " ")
20+
CDK.sharedLogger(.debug, "\(entityName):")
2121

2222
for (_key, value) in entity.userInfo! {
2323
let key = _key as! String
2424

2525
if !entityUserInfoKeys.contains(key) {
26-
CDK.sharedLogger(.DEBUG, "\(key)\(value)")
26+
CDK.sharedLogger(.debug, "\(key)\(value)")
2727
}
2828
}
2929

@@ -44,7 +44,7 @@ extension CoreDataStack {
4444
}
4545
}
4646

47-
private func dumpPropertyDescription(property: NSPropertyDescription, asIdentifyingAttribute: Bool = false) {
47+
fileprivate func dumpPropertyDescription(_ property: NSPropertyDescription, asIdentifyingAttribute: Bool = false) {
4848
var propertyUserInfoKeys = [MappingUserInfoKey]
4949
for i in 0...MaxNumberedMappings+1 {
5050
propertyUserInfoKeys.append(MappingUserInfoKey + ".\(i)")
@@ -54,20 +54,20 @@ extension CoreDataStack {
5454
let relationshipUserInfoKeys = [RelationTypeUserInfoKey]
5555

5656
let identifying = asIdentifyingAttribute ? "" : " "
57-
let indexed = property.indexed ? "" : ""
58-
let optional = property.optional ? "?" : ""
57+
let indexed = property.isIndexed ? "" : ""
58+
let optional = property.isOptional ? "?" : ""
5959
let relationshipType = (property as? NSRelationshipDescription)?.relationType.rawValue
6060
let relationshipTypeDescription = relationshipType == nil ? "" : "\(relationshipType!)"
6161

62-
CDK.sharedLogger(.DEBUG, "\(identifying)\(indexed)\(property.name)\(optional)\(property.mappings)\(relationshipTypeDescription)")
62+
CDK.sharedLogger(.debug, "\(identifying)\(indexed)\(property.name)\(optional)\(property.mappings)\(relationshipTypeDescription)")
6363

6464
for (_key, value) in property.userInfo! {
6565
let key = _key as! String
6666

6767
if !propertyUserInfoKeys.contains(key) {
6868
if (property is NSAttributeDescription && !attributeUserInfoKeys.contains(key)) ||
6969
(property is NSRelationshipDescription && !relationshipUserInfoKeys.contains(key)) {
70-
CDK.sharedLogger(.DEBUG, "\(key)\(value)")
70+
CDK.sharedLogger(.debug, "\(key)\(value)")
7171
}
7272
}
7373
}

CoreDataKit/Importing/JsonDecode+Importing.swift

+16-16
Original file line numberDiff line numberDiff line change
@@ -10,58 +10,58 @@ import Foundation
1010

1111
// We use the decode functions from the JsonDecode+Importing.swift file
1212
extension String {
13-
static func decode(json : AnyObject) -> String? {
13+
static func decode(_ json : AnyObject) -> String? {
1414
return json as? String
1515
}
1616
}
1717

1818
extension Bool {
19-
static func decode(json : AnyObject) -> Bool? {
19+
static func decode(_ json : AnyObject) -> Bool? {
2020
return json as? Bool
2121
}
2222
}
2323

2424
extension Int {
25-
static func decode(json : AnyObject) -> Int? {
25+
static func decode(_ json : AnyObject) -> Int? {
2626
return json as? Int
2727
}
2828
}
2929

3030
extension Int64 {
31-
static func decode(json : AnyObject) -> Int64? {
31+
static func decode(_ json : AnyObject) -> Int64? {
3232
let number = json as? NSNumber
33-
return number.map { $0.longLongValue }
33+
return number.map { $0.int64Value }
3434
}
3535
}
3636

3737
extension Double {
38-
static func decode(json : AnyObject) -> Double? {
38+
static func decode(_ json : AnyObject) -> Double? {
3939
return json as? Double
4040
}
4141
}
4242

43-
extension NSData {
44-
class func decode(json: AnyObject) -> NSData? {
45-
return json as? NSData
43+
extension Data {
44+
static func decode(_ json: AnyObject) -> Data? {
45+
return json as? Data
4646
}
4747
}
4848

49-
extension NSDate {
49+
extension Date {
5050
struct DateFormatter {
51-
static let withTimeZone : NSDateFormatter = {
52-
let formatter = NSDateFormatter()
51+
static let withTimeZone : Foundation.DateFormatter = {
52+
let formatter = Foundation.DateFormatter()
5353
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
54-
formatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
54+
formatter.locale = Locale(identifier: "en_US_POSIX")
5555

5656
return formatter
5757
}()
5858
}
5959

60-
class func decode(json : AnyObject) -> NSDate? {
61-
if let date = json as? NSDate {
60+
static func decode(_ json : AnyObject) -> Date? {
61+
if let date = json as? Date {
6262
return date
6363
} else if let dateString = json as? String {
64-
return DateFormatter.withTimeZone.dateFromString(dateString)
64+
return DateFormatter.withTimeZone.date(from: dateString)
6565
}
6666

6767
return nil

0 commit comments

Comments
 (0)