Skip to content

Commit 3debc82

Browse files
committed
updated to xcode 7
1 parent de1515a commit 3debc82

File tree

11 files changed

+100
-48
lines changed

11 files changed

+100
-48
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
###Task App for Swift that Persist Data with Core Data (iOS)
22
================
33

4-
#####Updated for Xcode 6.4 with Swift 1.2
4+
#####Updated for Xcode 7 with Swift 2.0
55

66
by: [Michael Crump](http://twitter.com/mbcrump)
77

TaskApplication.xcodeproj/project.pbxproj

+10-3
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@
168168
86FF5BA51A6D65FB00A017A1 /* Project object */ = {
169169
isa = PBXProject;
170170
attributes = {
171-
LastUpgradeCheck = 0610;
171+
LastSwiftMigration = 0700;
172+
LastSwiftUpdateCheck = 0700;
173+
LastUpgradeCheck = 0700;
172174
ORGANIZATIONNAME = "Michael Crump";
173175
TargetAttributes = {
174176
86FF5BAC1A6D65FB00A017A1 = {
@@ -292,6 +294,7 @@
292294
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
293295
COPY_PHASE_STRIP = NO;
294296
ENABLE_STRICT_OBJC_MSGSEND = YES;
297+
ENABLE_TESTABILITY = YES;
295298
GCC_C_LANGUAGE_STANDARD = gnu99;
296299
GCC_DYNAMIC_NO_PIC = NO;
297300
GCC_OPTIMIZATION_LEVEL = 0;
@@ -306,7 +309,7 @@
306309
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
307310
GCC_WARN_UNUSED_FUNCTION = YES;
308311
GCC_WARN_UNUSED_VARIABLE = YES;
309-
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
312+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
310313
MTL_ENABLE_DEBUG_INFO = YES;
311314
ONLY_ACTIVE_ARCH = YES;
312315
SDKROOT = iphoneos;
@@ -342,7 +345,7 @@
342345
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
343346
GCC_WARN_UNUSED_FUNCTION = YES;
344347
GCC_WARN_UNUSED_VARIABLE = YES;
345-
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
348+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
346349
MTL_ENABLE_DEBUG_INFO = NO;
347350
SDKROOT = iphoneos;
348351
VALIDATE_PRODUCT = YES;
@@ -358,6 +361,7 @@
358361
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
359362
INFOPLIST_FILE = TaskApplication/Info.plist;
360363
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
364+
PRODUCT_BUNDLE_IDENTIFIER = "net.michaelcrump.$(PRODUCT_NAME:rfc1034identifier)";
361365
PRODUCT_NAME = "$(TARGET_NAME)";
362366
PROVISIONING_PROFILE = "";
363367
};
@@ -372,6 +376,7 @@
372376
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
373377
INFOPLIST_FILE = TaskApplication/Info.plist;
374378
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
379+
PRODUCT_BUNDLE_IDENTIFIER = "net.michaelcrump.$(PRODUCT_NAME:rfc1034identifier)";
375380
PRODUCT_NAME = "$(TARGET_NAME)";
376381
PROVISIONING_PROFILE = "";
377382
};
@@ -391,6 +396,7 @@
391396
);
392397
INFOPLIST_FILE = TaskApplicationTests/Info.plist;
393398
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
399+
PRODUCT_BUNDLE_IDENTIFIER = "net.michaelcrump.$(PRODUCT_NAME:rfc1034identifier)";
394400
PRODUCT_NAME = "$(TARGET_NAME)";
395401
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TaskApplication.app/TaskApplication";
396402
};
@@ -406,6 +412,7 @@
406412
);
407413
INFOPLIST_FILE = TaskApplicationTests/Info.plist;
408414
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
415+
PRODUCT_BUNDLE_IDENTIFIER = "net.michaelcrump.$(PRODUCT_NAME:rfc1034identifier)";
409416
PRODUCT_NAME = "$(TARGET_NAME)";
410417
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TaskApplication.app/TaskApplication";
411418
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "58DEA5F9F78AED03F30276194337F64857474C9E",
3+
"DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : {
4+
5+
},
6+
"DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : {
7+
"9D491CFCEBD738578C711AFF792F576E6DC8ACC0" : 0,
8+
"58DEA5F9F78AED03F30276194337F64857474C9E" : 0
9+
},
10+
"DVTSourceControlWorkspaceBlueprintIdentifierKey" : "10EB1394-C6B0-462E-85C0-367571C298C7",
11+
"DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : {
12+
"9D491CFCEBD738578C711AFF792F576E6DC8ACC0" : "TaskApplication",
13+
"58DEA5F9F78AED03F30276194337F64857474C9E" : "TaskAppThatPersistData"
14+
},
15+
"DVTSourceControlWorkspaceBlueprintNameKey" : "TaskApplication",
16+
"DVTSourceControlWorkspaceBlueprintVersion" : 204,
17+
"DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "TaskApplication.xcodeproj",
18+
"DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [
19+
{
20+
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/mbcrump\/TasksForSwiftWithPersistingData",
21+
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
22+
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "58DEA5F9F78AED03F30276194337F64857474C9E"
23+
},
24+
{
25+
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/mbcrump\/TasksForSwift.git",
26+
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
27+
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "9D491CFCEBD738578C711AFF792F576E6DC8ACC0"
28+
}
29+
]
30+
}

TaskApplication.xcodeproj/xcuserdata/crump.xcuserdatad/xcschemes/TaskApplication.xcscheme

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0610"
3+
LastUpgradeVersion = "0700"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -37,10 +37,10 @@
3737
</BuildActionEntries>
3838
</BuildAction>
3939
<TestAction
40+
buildConfiguration = "Debug"
4041
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4142
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
42-
shouldUseLaunchSchemeArgsEnv = "YES"
43-
buildConfiguration = "Debug">
43+
shouldUseLaunchSchemeArgsEnv = "YES">
4444
<Testables>
4545
<TestableReference
4646
skipped = "NO">
@@ -62,17 +62,21 @@
6262
ReferencedContainer = "container:TaskApplication.xcodeproj">
6363
</BuildableReference>
6464
</MacroExpansion>
65+
<AdditionalOptions>
66+
</AdditionalOptions>
6567
</TestAction>
6668
<LaunchAction
69+
buildConfiguration = "Debug"
6770
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
6871
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
6972
launchStyle = "0"
7073
useCustomWorkingDirectory = "NO"
71-
buildConfiguration = "Debug"
7274
ignoresPersistentStateOnLaunch = "NO"
7375
debugDocumentVersioning = "YES"
76+
debugServiceExtension = "internal"
7477
allowLocationSimulation = "YES">
75-
<BuildableProductRunnable>
78+
<BuildableProductRunnable
79+
runnableDebuggingMode = "0">
7680
<BuildableReference
7781
BuildableIdentifier = "primary"
7882
BlueprintIdentifier = "86FF5BAC1A6D65FB00A017A1"
@@ -85,12 +89,13 @@
8589
</AdditionalOptions>
8690
</LaunchAction>
8791
<ProfileAction
92+
buildConfiguration = "Release"
8893
shouldUseLaunchSchemeArgsEnv = "YES"
8994
savedToolIdentifier = ""
9095
useCustomWorkingDirectory = "NO"
91-
buildConfiguration = "Release"
9296
debugDocumentVersioning = "YES">
93-
<BuildableProductRunnable>
97+
<BuildableProductRunnable
98+
runnableDebuggingMode = "0">
9499
<BuildableReference
95100
BuildableIdentifier = "primary"
96101
BlueprintIdentifier = "86FF5BAC1A6D65FB00A017A1"

TaskApplication/AppDelegate.swift

+23-21
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
4949
lazy var applicationDocumentsDirectory: NSURL = {
5050
// The directory the application uses to store the Core Data store file. This code uses a directory named "net.michaelcrump.CoreDataSample" in the application's documents Application Support directory.
5151
let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
52-
return urls[urls.count-1] as! NSURL
52+
return urls[urls.count-1]
5353
}()
5454

5555
lazy var managedObjectModel: NSManagedObjectModel = {
@@ -58,50 +58,52 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
5858
return NSManagedObjectModel(contentsOfURL: modelURL)!
5959
}()
6060

61-
lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator? = {
62-
// The persistent store coordinator for the application. This implementation creates and return a coordinator, having added the store for the application to it. This property is optional since there are legitimate error conditions that could cause the creation of the store to fail.
61+
lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator = {
62+
// The persistent store coordinator for the application. This implementation creates and returns a coordinator, having added the store for the application to it. This property is optional since there are legitimate error conditions that could cause the creation of the store to fail.
6363
// Create the coordinator and store
64-
var coordinator: NSPersistentStoreCoordinator? = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)
65-
let url = self.applicationDocumentsDirectory.URLByAppendingPathComponent("CoreDataSample.sqlite")
66-
var error: NSError? = nil
64+
let coordinator = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)
65+
let url = self.applicationDocumentsDirectory.URLByAppendingPathComponent("SingleViewCoreData.sqlite")
6766
var failureReason = "There was an error creating or loading the application's saved data."
68-
if coordinator!.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: nil, error: &error) == nil {
69-
coordinator = nil
67+
do {
68+
try coordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: nil)
69+
} catch {
7070
// Report any error we got.
71-
let dict = NSMutableDictionary()
71+
var dict = [String: AnyObject]()
7272
dict[NSLocalizedDescriptionKey] = "Failed to initialize the application's saved data"
7373
dict[NSLocalizedFailureReasonErrorKey] = failureReason
74-
dict[NSUnderlyingErrorKey] = error
75-
error = NSError(domain: "YOUR_ERROR_DOMAIN", code: 9999, userInfo: dict as [NSObject : AnyObject])
74+
75+
dict[NSUnderlyingErrorKey] = error as NSError
76+
let wrappedError = NSError(domain: "YOUR_ERROR_DOMAIN", code: 9999, userInfo: dict)
7677
// Replace this with code to handle the error appropriately.
7778
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
78-
NSLog("Unresolved error \(error), \(error!.userInfo)")
79+
NSLog("Unresolved error \(wrappedError), \(wrappedError.userInfo)")
7980
abort()
8081
}
8182

8283
return coordinator
8384
}()
8485

85-
lazy var managedObjectContext: NSManagedObjectContext? = {
86+
lazy var managedObjectContext: NSManagedObjectContext = {
8687
// Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.) This property is optional since there are legitimate error conditions that could cause the creation of the context to fail.
8788
let coordinator = self.persistentStoreCoordinator
88-
if coordinator == nil {
89-
return nil
90-
}
91-
var managedObjectContext = NSManagedObjectContext()
89+
var managedObjectContext = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType)
9290
managedObjectContext.persistentStoreCoordinator = coordinator
9391
return managedObjectContext
9492
}()
9593

9694
// MARK: - Core Data Saving support
9795

96+
// MARK: - Core Data Saving support
97+
9898
func saveContext () {
99-
if let moc = self.managedObjectContext {
100-
var error: NSError? = nil
101-
if moc.hasChanges && !moc.save(&error) {
99+
if managedObjectContext.hasChanges {
100+
do {
101+
try managedObjectContext.save()
102+
} catch {
102103
// Replace this implementation with code to handle the error appropriately.
103104
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
104-
NSLog("Unresolved error \(error), \(error!.userInfo)")
105+
let nserror = error as NSError
106+
NSLog("Unresolved error \(nserror), \(nserror.userInfo)")
105107
abort()
106108
}
107109
}

TaskApplication/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<key>CFBundleExecutable</key>
88
<string>$(EXECUTABLE_NAME)</string>
99
<key>CFBundleIdentifier</key>
10-
<string>net.michaelcrump.$(PRODUCT_NAME:rfc1034identifier)</string>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
1111
<key>CFBundleInfoDictionaryVersion</key>
1212
<string>6.0</string>
1313
<key>CFBundleName</key>

TaskApplication/PersistenceHelper.swift

+17-9
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,47 @@ class PersistenceHelper: NSObject {
1515
var context: NSManagedObjectContext;
1616

1717
override init(){
18-
context = appDel.managedObjectContext!
18+
context = appDel.managedObjectContext
1919
}
2020

2121
func save(entity: String, parameters: Dictionary<String,String> )->Bool{
2222

23-
var newEntity = NSEntityDescription.insertNewObjectForEntityForName(entity, inManagedObjectContext: context) as! NSManagedObject
23+
let newEntity = NSEntityDescription.insertNewObjectForEntityForName(entity, inManagedObjectContext: context)
2424
for (key, value) in parameters{
2525
newEntity.setValue(value, forKey: key)
2626
}
2727

28-
return context.save(nil)
28+
do {
29+
try context.save()
30+
return true
31+
} catch _ {
32+
return false
33+
}
2934
}
3035

3136
func list(entity: String ) ->NSArray{
3237

33-
var request = NSFetchRequest(entityName: entity)
38+
let request = NSFetchRequest(entityName: entity)
3439
request.returnsObjectsAsFaults = false;
35-
var results: NSArray = context.executeFetchRequest(request, error: nil)!
40+
let results: NSArray = try! context.executeFetchRequest(request)
3641
return results
3742
}
3843

3944
func remove(entity:String, key:String, value:String)->Bool{
4045

41-
var request = NSFetchRequest(entityName: entity)
46+
let request = NSFetchRequest(entityName: entity)
4247
request.returnsObjectsAsFaults = false
4348
request.predicate = NSPredicate(format: "\(key) = %@", value)
44-
var results: NSArray = context.executeFetchRequest(request, error: nil)!
49+
let results: NSArray = try! context.executeFetchRequest(request)
4550

4651
if(results.count>0){
4752

48-
var res = results[0] as! NSManagedObject
53+
let res = results[0] as! NSManagedObject
4954
context.deleteObject(res)
50-
context.save(nil)
55+
do {
56+
try context.save()
57+
} catch _ {
58+
}
5159
return true
5260
}
5361

TaskApplication/SecondViewController.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class SecondViewController: UIViewController, UITextFieldDelegate {
3030
//Task Title is blank, do not add a record
3131
} else {
3232
//add record
33-
var name: String = txtTask.text
34-
var description: String = txtDesc.text
33+
let name: String = txtTask.text!
34+
let description: String = txtDesc.text!
3535
taskMgr.addTask(name, desc: description)
3636

3737
//dismiss keyboard and reset fields
@@ -42,7 +42,7 @@ class SecondViewController: UIViewController, UITextFieldDelegate {
4242

4343
}
4444
}
45-
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
45+
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
4646
self.view.endEditing(true)
4747
}
4848

TaskApplication/TaskManager.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class TaskManager: NSObject {
2222

2323
override init(){
2424

25-
var tempTasks:NSArray = persistenceHelper.list("Task")
25+
let tempTasks:NSArray = persistenceHelper.list("Task")
2626
for res:AnyObject in tempTasks{
2727
tasks.append(Task(name:res.valueForKey("name")as! String,description:res.valueForKey("desc") as! String))
2828
}
@@ -42,7 +42,7 @@ class TaskManager: NSObject {
4242

4343
func removeTask(index:Int){
4444

45-
var value:String = tasks[index].name
45+
let value:String = tasks[index].name
4646

4747
if(persistenceHelper.remove("Task", key: "name", value: value)){
4848
tasks.removeAtIndex(index)

TaskApplicationTests/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<key>CFBundleExecutable</key>
88
<string>$(EXECUTABLE_NAME)</string>
99
<key>CFBundleIdentifier</key>
10-
<string>net.michaelcrump.$(PRODUCT_NAME:rfc1034identifier)</string>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
1111
<key>CFBundleInfoDictionaryVersion</key>
1212
<string>6.0</string>
1313
<key>CFBundleName</key>

0 commit comments

Comments
 (0)