@@ -12,15 +12,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
12
12
13
13
@IBOutlet var window : NSWindow ?
14
14
15
-
16
- func applicationDidFinishLaunching( aNotification: NSNotification ? ) {
17
- // Insert code here to initialize your application
18
- }
19
-
20
- func applicationWillTerminate( aNotification: NSNotification ? ) {
21
- // Insert code here to tear down your application
22
- }
23
-
24
15
@IBAction func saveAction( sender: AnyObject ) {
25
16
// Performs the save action for the application, which is to send the save: message to the application's managed object context. Any encountered errors are presented to the user.
26
17
var error : NSError ? = nil
@@ -30,7 +21,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
30
21
println ( " \( NSStringFromClass ( self . dynamicType) ) unable to commit editing before saving " )
31
22
}
32
23
if !moc. save ( & error) {
33
- NSApplication . sharedApplication ( ) . presentError ( error)
24
+ NSApplication . sharedApplication ( ) . presentError ( error! )
34
25
}
35
26
}
36
27
}
@@ -50,7 +41,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
50
41
}
51
42
52
43
let modelURL = NSBundle . mainBundle ( ) . URLForResource ( " MogenSwiftTest " , withExtension: " momd " )
53
- _managedObjectModel = NSManagedObjectModel ( contentsOfURL: modelURL)
44
+ _managedObjectModel = NSManagedObjectModel ( contentsOfURL: modelURL! )
54
45
return _managedObjectModel!
55
46
}
56
47
var _managedObjectModel : NSManagedObjectModel ? = nil
@@ -70,31 +61,31 @@ class AppDelegate: NSObject, NSApplicationDelegate {
70
61
let optProperties : NSDictionary ? = applicationFilesDirectory. resourceValuesForKeys ( [ NSURLIsDirectoryKey] , error: & error)
71
62
72
63
if let properties = optProperties {
73
- if !properties[ NSURLIsDirectoryKey] . boolValue {
64
+ if !properties[ NSURLIsDirectoryKey] ! . boolValue {
74
65
// Customize and localize this error.
75
66
let failureDescription = " Expected a folder to store application data, found a file \( applicationFilesDirectory. path) . "
76
- let dict = NSMutableDictionary ( )
77
- dict [ NSLocalizedDescriptionKey] = failureDescription
78
- error = NSError . errorWithDomain ( " YOUR_ERROR_DOMAIN " , code: 101 , userInfo: dict )
67
+ var errorDict = [ NSObject : AnyObject ] ( )
68
+ errorDict [ NSLocalizedDescriptionKey] = failureDescription
69
+ error = NSError ( domain : " YOUR_ERROR_DOMAIN " , code: 101 , userInfo: errorDict )
79
70
80
- NSApplication . sharedApplication ( ) . presentError ( error)
71
+ NSApplication . sharedApplication ( ) . presentError ( error! )
81
72
return nil
82
73
}
83
74
} else {
84
75
var ok = false
85
76
if error!. code == NSFileReadNoSuchFileError {
86
- ok = fileManager. createDirectoryAtPath ( applicationFilesDirectory. path, withIntermediateDirectories: true , attributes: nil , error: & error)
77
+ ok = fileManager. createDirectoryAtPath ( applicationFilesDirectory. path! , withIntermediateDirectories: true , attributes: nil , error: & error)
87
78
}
88
79
if !ok {
89
- NSApplication . sharedApplication ( ) . presentError ( error)
80
+ NSApplication . sharedApplication ( ) . presentError ( error! )
90
81
return nil
91
82
}
92
83
}
93
84
94
85
let url = applicationFilesDirectory. URLByAppendingPathComponent ( " MogenSwiftTest.storedata " )
95
86
var coordinator = NSPersistentStoreCoordinator ( managedObjectModel: mom)
96
87
if coordinator. addPersistentStoreWithType ( NSXMLStoreType, configuration: nil , URL: url, options: nil , error: & error) == nil {
97
- NSApplication . sharedApplication ( ) . presentError ( error)
88
+ NSApplication . sharedApplication ( ) . presentError ( error! )
98
89
return nil
99
90
}
100
91
_persistentStoreCoordinator = coordinator
@@ -110,11 +101,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
110
101
}
111
102
112
103
let coordinator = self . persistentStoreCoordinator
113
- if !coordinator {
114
- var dict = NSMutableDictionary ( )
115
- dict [ NSLocalizedDescriptionKey] = " Failed to initialize the store "
116
- dict [ NSLocalizedFailureReasonErrorKey] = " There was an error building up the data file. "
117
- let error = NSError . errorWithDomain ( " YOUR_ERROR_DOMAIN " , code: 9999 , userInfo: dict )
104
+ if !( coordinator != nil ) {
105
+ var errorDict = [ NSObject : AnyObject ] ( )
106
+ errorDict [ NSLocalizedDescriptionKey] = " Failed to initialize the store "
107
+ errorDict [ NSLocalizedFailureReasonErrorKey] = " There was an error building up the data file. "
108
+ let error = NSError ( domain : " YOUR_ERROR_DOMAIN " , code: 9999 , userInfo: errorDict )
118
109
NSApplication . sharedApplication ( ) . presentError ( error)
119
110
return nil
120
111
}
@@ -137,7 +128,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
137
128
func applicationShouldTerminate( sender: NSApplication ) -> NSApplicationTerminateReply {
138
129
// Save changes in the application's managed object context before the application terminates.
139
130
140
- if !_managedObjectContext {
131
+ if !( _managedObjectContext != nil ) {
141
132
// Accesses the underlying stored property because we don't want to cause the lazy initialization
142
133
return . TerminateNow
143
134
}
@@ -154,7 +145,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
154
145
var error : NSError ? = nil
155
146
if !moc. save ( & error) {
156
147
// Customize this code block to include application-specific recovery steps.
157
- let result = sender. presentError ( error)
148
+ let result = sender. presentError ( error! )
158
149
if ( result) {
159
150
return . TerminateCancel
160
151
}
0 commit comments