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

Commit bd45035

Browse files
committed
Initial conversion
1 parent ed25409 commit bd45035

8 files changed

+44
-31
lines changed

CoreDataKit.xcodeproj/project.pbxproj

+15-1
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 = {
@@ -310,6 +310,7 @@
310310
D5D7C6C61958B8CF0048B576 = {
311311
CreatedOnToolsVersion = 6.0;
312312
LastSwiftMigration = 0800;
313+
ProvisioningStyle = Automatic;
313314
TestTargetID = D5D7C6BB1958B8CF0048B576;
314315
};
315316
};
@@ -429,8 +430,10 @@
429430
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
430431
CLANG_WARN_EMPTY_BODY = YES;
431432
CLANG_WARN_ENUM_CONVERSION = YES;
433+
CLANG_WARN_INFINITE_RECURSION = YES;
432434
CLANG_WARN_INT_CONVERSION = YES;
433435
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
436+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
434437
CLANG_WARN_UNREACHABLE_CODE = YES;
435438
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
436439
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -440,6 +443,7 @@
440443
ENABLE_TESTABILITY = YES;
441444
GCC_C_LANGUAGE_STANDARD = gnu99;
442445
GCC_DYNAMIC_NO_PIC = NO;
446+
GCC_NO_COMMON_BLOCKS = YES;
443447
GCC_OPTIMIZATION_LEVEL = 0;
444448
GCC_PREPROCESSOR_DEFINITIONS = (
445449
"DEBUG=1",
@@ -476,8 +480,10 @@
476480
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
477481
CLANG_WARN_EMPTY_BODY = YES;
478482
CLANG_WARN_ENUM_CONVERSION = YES;
483+
CLANG_WARN_INFINITE_RECURSION = YES;
479484
CLANG_WARN_INT_CONVERSION = YES;
480485
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
486+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
481487
CLANG_WARN_UNREACHABLE_CODE = YES;
482488
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
483489
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -486,6 +492,7 @@
486492
ENABLE_NS_ASSERTIONS = NO;
487493
ENABLE_STRICT_OBJC_MSGSEND = YES;
488494
GCC_C_LANGUAGE_STANDARD = gnu99;
495+
GCC_NO_COMMON_BLOCKS = YES;
489496
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
490497
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
491498
GCC_WARN_UNDECLARED_SELECTOR = YES;
@@ -495,6 +502,7 @@
495502
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
496503
METAL_ENABLE_DEBUG_INFO = NO;
497504
SDKROOT = iphoneos;
505+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
498506
TARGETED_DEVICE_FAMILY = "1,2";
499507
VALIDATE_PRODUCT = YES;
500508
VERSIONING_SYSTEM = "apple-generic";
@@ -506,6 +514,7 @@
506514
isa = XCBuildConfiguration;
507515
buildSettings = {
508516
CLANG_ENABLE_MODULES = YES;
517+
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
509518
DEFINES_MODULE = YES;
510519
DYLIB_COMPATIBILITY_VERSION = 1;
511520
DYLIB_CURRENT_VERSION = 1;
@@ -526,6 +535,7 @@
526535
isa = XCBuildConfiguration;
527536
buildSettings = {
528537
CLANG_ENABLE_MODULES = YES;
538+
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
529539
DEFINES_MODULE = YES;
530540
DYLIB_COMPATIBILITY_VERSION = 1;
531541
DYLIB_CURRENT_VERSION = 1;
@@ -544,6 +554,8 @@
544554
D5D7C6D61958B8CF0048B576 /* Debug */ = {
545555
isa = XCBuildConfiguration;
546556
buildSettings = {
557+
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
558+
DEVELOPMENT_TEAM = "";
547559
FRAMEWORK_SEARCH_PATHS = (
548560
"$(SDKROOT)/Developer/Library/Frameworks",
549561
"$(inherited)",
@@ -564,6 +576,8 @@
564576
D5D7C6D71958B8CF0048B576 /* Release */ = {
565577
isa = XCBuildConfiguration;
566578
buildSettings = {
579+
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
580+
DEVELOPMENT_TEAM = "";
567581
FRAMEWORK_SEARCH_PATHS = (
568582
"$(SDKROOT)/Developer/Library/Frameworks",
569583
"$(inherited)",

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,17 @@ public class CDK : NSObject
8282

8383
:see: NSManagedObjectContext.performBlock()
8484
*/
85-
public class func performOnBackgroundContext(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

8989
@available(*, unavailable, renamed: "performOnBackgroundContext(block:completionHandler:)")
9090
public class func performBlockOnBackgroundContext(_ block: PerformBlock, completionHandler: PerformBlockCompletionHandler?) {
9191
fatalError()
9292
}
9393

94-
public class func performOnBackgroundContext(_ block: PerformBlock) {
95-
sharedStack!.performBlockOnBackgroundContext(block, completionHandler: nil)
94+
public class func performOnBackgroundContext(block: @escaping PerformBlock) {
95+
sharedStack!.performOnBackgroundContext(block: block, completionHandler: nil)
9696
}
9797

9898
@available(*, unavailable, renamed: "performOnBackgroundContext(block:)")

CoreDataKit/CoreDataStack.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,21 @@ public class CoreDataStack: NSObject {
5656

5757
:see: NSManagedObjectContext.performBlock()
5858
*/
59-
public func performOnBackgroundContext(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

6363
@available(*, unavailable, renamed: "performOnBackgroundContext(block:completionHandler:)")
6464
public func performBlockOnBackgroundContext(_ block: PerformBlock, completionHandler: PerformBlockCompletionHandler?) {
6565
fatalError()
6666
}
6767

68-
public func performOnBackgroundContext(block: PerformBlock) {
69-
backgroundContext.performBlock(block, completionHandler: nil)
68+
public func performOnBackgroundContext(block: @escaping PerformBlock) {
69+
backgroundContext.perform(block: block, completionHandler: nil)
7070
}
7171

7272
@available(*, unavailable, renamed: "performOnBackgroundContext(block:)")
73-
public func performBlockOnBackgroundContext(_ block: PerformBlock, completionHandler: PerformBlockCompletionHandler?) {
73+
public func performBlockOnBackgroundContext(_ block: PerformBlock) {
7474
fatalError()
7575
}
7676

CoreDataKit/Importing/NSAttributeDescription+Importing.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extension NSAttributeDescription
2222
case .integer16AttributeType:
2323
fallthrough
2424
case .integer32AttributeType:
25-
return Int.decode(value)
25+
return Int.decode(value) as AnyObject?
2626

2727
case .integer64AttributeType:
2828
if let int64 = Int64.decode(value) {
@@ -36,19 +36,19 @@ extension NSAttributeDescription
3636
case .doubleAttributeType:
3737
fallthrough
3838
case .floatAttributeType:
39-
return Double.decode(value)
39+
return Double.decode(value) as AnyObject?
4040

4141
case .stringAttributeType:
42-
return String.decode(value)
42+
return String.decode(value) as AnyObject?
4343

4444
case .booleanAttributeType:
45-
return Bool.decode(value)
45+
return Bool.decode(value) as AnyObject?
4646

4747
case .dateAttributeType:
48-
return Date.decode(value)
48+
return Date.decode(value) as AnyObject?
4949

5050
case .binaryDataAttributeType:
51-
return Data.decode(value)
51+
return Data.decode(value) as AnyObject?
5252

5353
case .undefinedAttributeType:
5454
fallthrough

CoreDataKit/Importing/NSManagedObject+Importing.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ extension NSManagedObject
1818
- returns: Result wheter the import was performed
1919
*/
2020
public func importDictionary(_ dictionary: [String: AnyObject]) throws {
21-
if shouldImport(dictionary) {
22-
let transformedDictionary = willImport(dictionary)
21+
if shouldImport(dictionary: dictionary) {
22+
let transformedDictionary = willImport(dictionary: dictionary)
2323
do {
2424
try performImport(dictionary: transformedDictionary)
25-
didImport(transformedDictionary, error: nil)
25+
didImport(dictionary: transformedDictionary, error: nil)
2626
}
2727
catch let err {
28-
didImport(transformedDictionary, error: err)
28+
didImport(dictionary: transformedDictionary, error: err)
2929
throw err
3030
}
3131

@@ -136,7 +136,7 @@ extension NSManagedObject
136136
fileprivate func performImportAttribute(_ attribute: NSAttributeDescription, dictionary: [String: AnyObject]) throws {
137137
switch attribute.preferredValueFromDictionary(dictionary) {
138138
case let .some(value):
139-
if let transformedValue: AnyObject = attribute.transformValue(value) {
139+
if let transformedValue: AnyObject = attribute.transform(value: value) {
140140
setValue(transformedValue, forKeyPath: attribute.name)
141141
} else {
142142
let error = CoreDataKitError.importError(description: "Value '\(value)' could not be transformed to a value compatible with the type of \(entity.name).\(attribute.name)")

CoreDataKit/NSManagedObjectContext.swift

+7-8
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ extension NSManagedObjectContext
253253

254254
- returns: Result with NSFetchRequest configured with the given parameters
255255
*/
256-
public func createFetchRequest<T:NSManagedObject>(_ entity: T.Type, predicate: NSPredicate? = nil, sortDescriptors: [NSSortDescriptor]? = nil, limit: Int? = nil, offset: Int? = nil) throws -> NSFetchRequest<AnyObject> where T:NamedManagedObject {
256+
public func createFetchRequest<T : NSManagedObject>(_ entity: T.Type, predicate: NSPredicate? = nil, sortDescriptors: [NSSortDescriptor]? = nil, limit: Int? = nil, offset: Int? = nil) throws -> NSFetchRequest<T> where T:NamedManagedObject {
257257
let desc = try entityDescription(entity)
258258
return self.createFetchRequest(desc, predicate: predicate, sortDescriptors: sortDescriptors, limit: limit, offset: offset)
259259
}
@@ -269,8 +269,8 @@ extension NSManagedObjectContext
269269

270270
- returns: NSFetchRequest configured with the given parameters
271271
*/
272-
public func createFetchRequest(_ entityDescription: NSEntityDescription, predicate: NSPredicate? = nil, sortDescriptors: [NSSortDescriptor]? = nil, limit: Int? = nil, offset: Int? = nil) -> NSFetchRequest<AnyObject> {
273-
let fetchRequest = NSFetchRequest()
272+
public func createFetchRequest<ResultType : NSFetchRequestResult>(_ entityDescription: NSEntityDescription, predicate: NSPredicate? = nil, sortDescriptors: [NSSortDescriptor]? = nil, limit: Int? = nil, offset: Int? = nil) -> NSFetchRequest<ResultType> {
273+
let fetchRequest = NSFetchRequest<ResultType>()
274274
fetchRequest.entity = entityDescription
275275
fetchRequest.predicate = predicate
276276
fetchRequest.sortDescriptors = sortDescriptors
@@ -288,10 +288,9 @@ extension NSManagedObjectContext
288288

289289
- returns: Result with array of entities found, empty array on no results
290290
*/
291-
public func executeFetchRequest<T:NSManagedObject>(_ fetchRequest: NSFetchRequest<AnyObject>) throws -> [T] {
291+
public func executeFetchRequest<T : NSManagedObject>(_ fetchRequest: NSFetchRequest<T>) throws -> [T] {
292292
do {
293-
let anyObjects = try fetch(fetchRequest)
294-
return anyObjects.map { $0 as! T }
293+
return try fetch(fetchRequest)
295294
}
296295
catch {
297296
throw CoreDataKitError.coreDataError(error)
@@ -312,7 +311,7 @@ extension NSManagedObjectContext
312311

313312
- returns: Fetched results controller that already has performed the fetch
314313
*/
315-
public func fetchedResultsController(_ fetchRequest: NSFetchRequest, delegate: NSFetchedResultsControllerDelegate? = nil, sectionNameKeyPath: String? = nil, cacheName: String? = nil) throws -> NSFetchedResultsController<AnyObject> {
314+
public func fetchedResultsController<ResultType : NSFetchRequestResult>(_ fetchRequest: NSFetchRequest<ResultType>, delegate: NSFetchedResultsControllerDelegate? = nil, sectionNameKeyPath: String? = nil, cacheName: String? = nil) throws -> NSFetchedResultsController<ResultType> {
316315
let resultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: self, sectionNameKeyPath: sectionNameKeyPath, cacheName: cacheName)
317316
resultsController.delegate = delegate
318317

@@ -390,7 +389,7 @@ extension NSManagedObjectContext
390389
- returns: Result with array of entities found, empty array on no results
391390
*/
392391
func find<T:NSManagedObject>(_ entityDescription: NSEntityDescription, predicate: NSPredicate? = nil, sortDescriptors: [NSSortDescriptor]? = nil, limit: Int? = nil, offset: Int? = nil) throws -> [T] {
393-
let fetchRequest = createFetchRequest(entityDescription, predicate: predicate, sortDescriptors: sortDescriptors, limit: limit)
392+
let fetchRequest: NSFetchRequest<T> = createFetchRequest(entityDescription, predicate: predicate, sortDescriptors: sortDescriptors, limit: limit)
394393
return try executeFetchRequest(fetchRequest)
395394
}
396395

CoreDataKit/NSPersistentStoreCoordinator.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extension NSPersistentStoreCoordinator
2323

2424
// Fallback on the defaults
2525
let _managedObjectModel = optionalManagedObjectModel ?? NSManagedObjectModel.mergedModel(from: nil)
26-
let _URL = optionalURL ?? NSPersistentStore.URLForSQLiteStoreName("CoreDataKit")
26+
let _URL = optionalURL ?? NSPersistentStore.url(forSQLiteStoreName: "CoreDataKit")
2727

2828
// Initialize coordinator if we have all data
2929
if let managedObjectModel = _managedObjectModel, let URL = _URL {

0 commit comments

Comments
 (0)