Skip to content

Commit aa41b82

Browse files
committed
TopHits example app works again.
1 parent 64503f4 commit aa41b82

File tree

7 files changed

+95
-119
lines changed

7 files changed

+95
-119
lines changed

Examples/TopHits/TopHits.xcodeproj/project.pbxproj

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
F340B32F1C40EB31008CF49E /* Artist+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = F340B3231C40EB31008CF49E /* Artist+CoreDataProperties.swift */; };
1717
F340B3301C40EB31008CF49E /* ArtistAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = F340B3241C40EB31008CF49E /* ArtistAttribute.swift */; };
1818
F340B3311C40EB31008CF49E /* CoreDataController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F340B3251C40EB31008CF49E /* CoreDataController.swift */; };
19-
F340B3321C40EB31008CF49E /* NSManagedObjectContextExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F340B3261C40EB31008CF49E /* NSManagedObjectContextExtensions.swift */; };
2019
F340B3331C40EB31008CF49E /* SearchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F340B3271C40EB31008CF49E /* SearchViewController.swift */; };
2120
F340B3341C40EB31008CF49E /* Song.swift in Sources */ = {isa = PBXBuildFile; fileRef = F340B3281C40EB31008CF49E /* Song.swift */; };
2221
F340B3351C40EB31008CF49E /* Song+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = F340B3291C40EB31008CF49E /* Song+CoreDataProperties.swift */; };
@@ -114,7 +113,6 @@
114113
F340B3231C40EB31008CF49E /* Artist+CoreDataProperties.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Artist+CoreDataProperties.swift"; sourceTree = "<group>"; };
115114
F340B3241C40EB31008CF49E /* ArtistAttribute.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArtistAttribute.swift; sourceTree = "<group>"; };
116115
F340B3251C40EB31008CF49E /* CoreDataController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataController.swift; sourceTree = "<group>"; };
117-
F340B3261C40EB31008CF49E /* NSManagedObjectContextExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSManagedObjectContextExtensions.swift; sourceTree = "<group>"; };
118116
F340B3271C40EB31008CF49E /* SearchViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchViewController.swift; sourceTree = "<group>"; };
119117
F340B3281C40EB31008CF49E /* Song.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Song.swift; sourceTree = "<group>"; };
120118
F340B3291C40EB31008CF49E /* Song+CoreDataProperties.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Song+CoreDataProperties.swift"; sourceTree = "<group>"; };
@@ -187,7 +185,6 @@
187185
F340B3231C40EB31008CF49E /* Artist+CoreDataProperties.swift */,
188186
F340B3241C40EB31008CF49E /* ArtistAttribute.swift */,
189187
F340B3251C40EB31008CF49E /* CoreDataController.swift */,
190-
F340B3261C40EB31008CF49E /* NSManagedObjectContextExtensions.swift */,
191188
F340B3281C40EB31008CF49E /* Song.swift */,
192189
F340B3291C40EB31008CF49E /* Song+CoreDataProperties.swift */,
193190
F340B32A1C40EB31008CF49E /* SongAttribute.swift */,
@@ -241,11 +238,12 @@
241238
isa = PBXProject;
242239
attributes = {
243240
LastSwiftUpdateCheck = 0720;
244-
LastUpgradeCheck = 0720;
241+
LastUpgradeCheck = 0800;
245242
ORGANIZATIONNAME = "Prosumma LLC";
246243
TargetAttributes = {
247244
F340B3021C40EA08008CF49E = {
248245
CreatedOnToolsVersion = 7.2;
246+
LastSwiftMigration = 0800;
249247
};
250248
};
251249
};
@@ -352,7 +350,7 @@
352350
);
353351
runOnlyForDeploymentPostprocessing = 0;
354352
shellPath = /bin/sh;
355-
shellScript = "TARGET_DIR=\"${PROJECT_DIR}/${TARGET_NAME}\"\nCDQI=\"$(dirname $(dirname ${PROJECT_DIR}))/bin/cdqi\"\n# for carthage install use ${PROJECT_DIR}/Carthage/Checkouts/CoreDataQueryInterface/bin/cdqi\n\nfor f in $(find $TARGET_DIR -name \"*.xcdatamodeld\")\ndo\n FILENAME=\"$(basename $f)\"\n MODEL_DIR=\"$(dirname $f)\"\n MODEL=${FILENAME%.*}\n echo \"Generating model attributes for ${f}\"\n $($CDQI --in $MODEL_DIR --force \"${MODEL}\")\ndone";
353+
shellScript = "TARGET_DIR=\"${PROJECT_DIR}/${TARGET_NAME}\"\nCDQI=\"$(dirname $(dirname ${PROJECT_DIR}))/bin/cdqi\"\n# for carthage install use ${PROJECT_DIR}/Carthage/Checkouts/CoreDataQueryInterface/bin/cdqi\n\n#for f in $(find $TARGET_DIR -name \"*.xcdatamodeld\")\n#do\n# FILENAME=\"$(basename $f)\"\n# MODEL_DIR=\"$(dirname $f)\"\n# MODEL=${FILENAME%.*}\n# echo \"Generating model attributes for ${f}\"\n# $($CDQI --in $MODEL_DIR --force \"${MODEL}\")\n#done";
356354
};
357355
/* End PBXShellScriptBuildPhase section */
358356

@@ -366,7 +364,6 @@
366364
F340B32F1C40EB31008CF49E /* Artist+CoreDataProperties.swift in Sources */,
367365
F340B3381C40EB31008CF49E /* UIViewControllerExtensions.swift in Sources */,
368366
F340B3391C40EB31008CF49E /* SetupViewController.swift in Sources */,
369-
F340B3321C40EB31008CF49E /* NSManagedObjectContextExtensions.swift in Sources */,
370367
F340B3331C40EB31008CF49E /* SearchViewController.swift in Sources */,
371368
F340B3351C40EB31008CF49E /* Song+CoreDataProperties.swift in Sources */,
372369
F340B32E1C40EB31008CF49E /* Artist.swift in Sources */,
@@ -421,8 +418,10 @@
421418
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
422419
CLANG_WARN_EMPTY_BODY = YES;
423420
CLANG_WARN_ENUM_CONVERSION = YES;
421+
CLANG_WARN_INFINITE_RECURSION = YES;
424422
CLANG_WARN_INT_CONVERSION = YES;
425423
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
424+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
426425
CLANG_WARN_UNREACHABLE_CODE = YES;
427426
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
428427
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -444,7 +443,7 @@
444443
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
445444
GCC_WARN_UNUSED_FUNCTION = YES;
446445
GCC_WARN_UNUSED_VARIABLE = YES;
447-
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
446+
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
448447
MTL_ENABLE_DEBUG_INFO = YES;
449448
ONLY_ACTIVE_ARCH = YES;
450449
SDKROOT = iphoneos;
@@ -466,8 +465,10 @@
466465
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
467466
CLANG_WARN_EMPTY_BODY = YES;
468467
CLANG_WARN_ENUM_CONVERSION = YES;
468+
CLANG_WARN_INFINITE_RECURSION = YES;
469469
CLANG_WARN_INT_CONVERSION = YES;
470470
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
471+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
471472
CLANG_WARN_UNREACHABLE_CODE = YES;
472473
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
473474
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -483,9 +484,10 @@
483484
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
484485
GCC_WARN_UNUSED_FUNCTION = YES;
485486
GCC_WARN_UNUSED_VARIABLE = YES;
486-
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
487+
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
487488
MTL_ENABLE_DEBUG_INFO = NO;
488489
SDKROOT = iphoneos;
490+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
489491
TARGETED_DEVICE_FAMILY = "1,2";
490492
VALIDATE_PRODUCT = YES;
491493
};
@@ -494,27 +496,29 @@
494496
F340B3161C40EA08008CF49E /* Debug */ = {
495497
isa = XCBuildConfiguration;
496498
buildSettings = {
499+
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
497500
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
498501
CLANG_ENABLE_MODULES = YES;
499-
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
500502
INFOPLIST_FILE = TopHits/Info.plist;
501503
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
502504
PRODUCT_BUNDLE_IDENTIFIER = com.prosumma.TopHits;
503505
PRODUCT_NAME = "$(TARGET_NAME)";
504506
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
507+
SWIFT_VERSION = 3.0;
505508
};
506509
name = Debug;
507510
};
508511
F340B3171C40EA08008CF49E /* Release */ = {
509512
isa = XCBuildConfiguration;
510513
buildSettings = {
514+
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
511515
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
512516
CLANG_ENABLE_MODULES = YES;
513-
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
514517
INFOPLIST_FILE = TopHits/Info.plist;
515518
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
516519
PRODUCT_BUNDLE_IDENTIFIER = com.prosumma.TopHits;
517520
PRODUCT_NAME = "$(TARGET_NAME)";
521+
SWIFT_VERSION = 3.0;
518522
};
519523
name = Release;
520524
};
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
//
2-
// Generated by CDQI on 2016-04-30.
2+
// Generated by CDQI on 2016-10-09.
33
//
44
// This file was generated by a tool. Further invocations of this tool will overwrite this file.
55
// Edit it at your own risk.
66
//
77

88
import CoreDataQueryInterface
99

10-
class ArtistAttribute: EntityAttribute, Aggregable {
11-
private(set) lazy var name: StringAttribute = { StringAttribute("name", parent: self) }()
12-
private(set) lazy var songs: SongAttribute = { SongAttribute("songs", parent: self) }()
10+
final class ArtistAttribute: EntityAttribute, Subqueryable {
11+
private(set) lazy var name: StringAttribute = { StringAttribute(key: "name", parent: self) }()
12+
private(set) lazy var songs: SongAttribute = { SongAttribute(key: "songs", parent: self) }()
1313
}
1414

15-
extension Artist: EntityType {
16-
typealias EntityAttributeType = ArtistAttribute
15+
extension Artist: Entity {
16+
typealias CDQIAttribute = ArtistAttribute
1717
}
1818

Examples/TopHits/TopHits/CoreDataController.swift

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ class CoreDataController {
3030
static let ProgressNotification = "CoreDataControllerProgressNotification"
3131
static let sharedInstance = CoreDataController()
3232

33-
private init() {}
33+
fileprivate init() {}
3434

35-
let managedObjectContext = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType)
35+
let managedObjectContext = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)
3636

37-
func setup(completion: () -> Void) {
37+
func setup(_ completion: @escaping () -> Void) {
3838
let databaseFileName = "TopHits.db"
39-
let fileManager = NSFileManager.defaultManager()
40-
let documentPath = try! fileManager.URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: false)
41-
let databasePath = documentPath.URLByAppendingPathComponent(databaseFileName)
42-
let shouldCreateDatabase = !fileManager.fileExistsAtPath(databasePath.path!)
43-
let managedObjectModel = NSManagedObjectModel.mergedModelFromBundles(nil)!
39+
let fileManager = FileManager.default
40+
let documentPath = try! fileManager.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
41+
let databasePath = documentPath.appendingPathComponent(databaseFileName)
42+
let shouldCreateDatabase = !fileManager.fileExists(atPath: databasePath.path)
43+
let managedObjectModel = NSManagedObjectModel.mergedModel(from: nil)!
4444
let persistentStoreCoordinator = NSPersistentStoreCoordinator(managedObjectModel: managedObjectModel)
45-
try! persistentStoreCoordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: databasePath, options: nil)
45+
try! persistentStoreCoordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: databasePath, options: nil)
4646
let finish: () -> Void = {
4747
self.managedObjectContext.persistentStoreCoordinator = persistentStoreCoordinator
4848
completion()
@@ -54,44 +54,44 @@ class CoreDataController {
5454
}
5555
}
5656

57-
private func createDatabase(path: NSURL, persistentStoreCoordinator: NSPersistentStoreCoordinator, completion: () -> Void) {
58-
let managedObjectContext = NSManagedObjectContext(concurrencyType: .PrivateQueueConcurrencyType)
57+
fileprivate func createDatabase(_ path: URL, persistentStoreCoordinator: NSPersistentStoreCoordinator, completion: @escaping () -> Void) {
58+
let managedObjectContext = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
5959
managedObjectContext.persistentStoreCoordinator = persistentStoreCoordinator
60-
managedObjectContext.performBlock {
60+
managedObjectContext.perform {
6161
let YEAR = 0
6262
let POSITION = 1
6363
let ARTIST = 2
6464
let SONG = 3
6565
let FIELD_COUNT = 4
6666

67-
let numberFormatter = NSNumberFormatter()
68-
let dataPath = NSBundle.mainBundle().pathForResource("TopHits", ofType: "psv")!
67+
let numberFormatter = NumberFormatter()
68+
let dataPath = Bundle.main.path(forResource: "TopHits", ofType: "psv")!
6969
let data = try! String(contentsOfFile: dataPath)
7070
var previousYear: NSNumber? = nil
71-
for line in data.componentsSeparatedByString("\n") {
72-
let fields = line.componentsSeparatedByString("|")
71+
for line in data.components(separatedBy: "\n") {
72+
let fields = line.components(separatedBy: "|")
7373
if fields.count != FIELD_COUNT { continue }
74-
let year = numberFormatter.numberFromString(fields[YEAR])!
74+
let year = numberFormatter.number(from: fields[YEAR])!
7575
if year != previousYear {
76-
dispatch_async(dispatch_get_main_queue()) {
76+
DispatchQueue.main.async {
7777
let userInfo = ["year": year]
78-
NSNotificationCenter.defaultCenter().postNotificationName(CoreDataController.ProgressNotification, object: self, userInfo: userInfo)
78+
NotificationCenter.default.post(name: Notification.Name(rawValue: CoreDataController.ProgressNotification), object: self, userInfo: userInfo)
7979
}
8080
previousYear = year
8181
}
82-
let position = numberFormatter.numberFromString(fields[POSITION])!
82+
let position = numberFormatter.number(from: fields[POSITION])!
8383
let artistName = fields[ARTIST]
8484
let songName = fields[SONG]
85-
let artist = managedObjectContext.from(Artist).filter({$0.name == artistName}).first() ?? managedObjectContext.newEntity(Artist)
85+
let artist = try! managedObjectContext.from(Artist.self).filter({$0.name == artistName}).first() ?? managedObjectContext.cdqiNewEntity(Artist.self)
8686
artist.name = artistName
87-
let song = managedObjectContext.newEntity(Song)
88-
song.year = year.intValue
89-
song.position = position.intValue
87+
let song = managedObjectContext.cdqiNewEntity(Song.self)
88+
song.year = Int32(year.intValue)
89+
song.position = Int32(position.intValue)
9090
song.name = songName
9191
song.artist = artist
9292
}
9393
try! managedObjectContext.save()
94-
dispatch_async(dispatch_get_main_queue(), completion)
94+
DispatchQueue.main.async(execute: completion)
9595
}
9696
}
9797
}

Examples/TopHits/TopHits/NSManagedObjectContextExtensions.swift

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)