Skip to content

Commit 517e527

Browse files
author
Justin Williams
committed
[FIX] MogenSwiftTest main target compiles. Test target is still hosed. Waiting on Swift 1.2 PR's.
1 parent 5983bf0 commit 517e527

File tree

6 files changed

+32
-41
lines changed

6 files changed

+32
-41
lines changed

test/MogenSwiftTest/MogenSwiftTest/AppDelegate.swift

+17-26
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
1212

1313
@IBOutlet var window: NSWindow?
1414

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-
2415
@IBAction func saveAction(sender: AnyObject) {
2516
// 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.
2617
var error: NSError? = nil
@@ -30,7 +21,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
3021
println("\(NSStringFromClass(self.dynamicType)) unable to commit editing before saving")
3122
}
3223
if !moc.save(&error) {
33-
NSApplication.sharedApplication().presentError(error)
24+
NSApplication.sharedApplication().presentError(error!)
3425
}
3526
}
3627
}
@@ -50,7 +41,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
5041
}
5142

5243
let modelURL = NSBundle.mainBundle().URLForResource("MogenSwiftTest", withExtension: "momd")
53-
_managedObjectModel = NSManagedObjectModel(contentsOfURL: modelURL)
44+
_managedObjectModel = NSManagedObjectModel(contentsOfURL: modelURL!)
5445
return _managedObjectModel!
5546
}
5647
var _managedObjectModel: NSManagedObjectModel? = nil
@@ -70,31 +61,31 @@ class AppDelegate: NSObject, NSApplicationDelegate {
7061
let optProperties: NSDictionary? = applicationFilesDirectory.resourceValuesForKeys([NSURLIsDirectoryKey], error: &error)
7162

7263
if let properties = optProperties {
73-
if !properties[NSURLIsDirectoryKey].boolValue {
64+
if !properties[NSURLIsDirectoryKey]!.boolValue {
7465
// Customize and localize this error.
7566
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)
7970

80-
NSApplication.sharedApplication().presentError(error)
71+
NSApplication.sharedApplication().presentError(error!)
8172
return nil
8273
}
8374
} else {
8475
var ok = false
8576
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)
8778
}
8879
if !ok {
89-
NSApplication.sharedApplication().presentError(error)
80+
NSApplication.sharedApplication().presentError(error!)
9081
return nil
9182
}
9283
}
9384

9485
let url = applicationFilesDirectory.URLByAppendingPathComponent("MogenSwiftTest.storedata")
9586
var coordinator = NSPersistentStoreCoordinator(managedObjectModel: mom)
9687
if coordinator.addPersistentStoreWithType(NSXMLStoreType, configuration: nil, URL: url, options: nil, error: &error) == nil {
97-
NSApplication.sharedApplication().presentError(error)
88+
NSApplication.sharedApplication().presentError(error!)
9889
return nil
9990
}
10091
_persistentStoreCoordinator = coordinator
@@ -110,11 +101,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
110101
}
111102

112103
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)
118109
NSApplication.sharedApplication().presentError(error)
119110
return nil
120111
}
@@ -137,7 +128,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
137128
func applicationShouldTerminate(sender: NSApplication) -> NSApplicationTerminateReply {
138129
// Save changes in the application's managed object context before the application terminates.
139130

140-
if !_managedObjectContext {
131+
if !(_managedObjectContext != nil) {
141132
// Accesses the underlying stored property because we don't want to cause the lazy initialization
142133
return .TerminateNow
143134
}
@@ -154,7 +145,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
154145
var error: NSError? = nil
155146
if !moc.save(&error) {
156147
// Customize this code block to include application-specific recovery steps.
157-
let result = sender.presentError(error)
148+
let result = sender.presentError(error!)
158149
if (result) {
159150
return .TerminateCancel
160151
}

test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/_MyEntityMO.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class _MyEntityMO: NSManagedObject {
2323

2424
/// pragma mark - Life cycle methods
2525

26-
init(entity: NSEntityDescription!, insertIntoManagedObjectContext context: NSManagedObjectContext!) {
26+
override init(entity: NSEntityDescription, insertIntoManagedObjectContext context: NSManagedObjectContext?) {
2727
super.init(entity: entity, insertIntoManagedObjectContext: context)
2828
}
2929

test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/_UnorderedToManyDstMO.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class _UnorderedToManyDstMO: NSManagedObject {
2626

2727
/// pragma mark - Life cycle methods
2828

29-
init(entity: NSEntityDescription!, insertIntoManagedObjectContext context: NSManagedObjectContext!) {
29+
override init(entity: NSEntityDescription, insertIntoManagedObjectContext context: NSManagedObjectContext?) {
3030
super.init(entity: entity, insertIntoManagedObjectContext: context)
3131
}
3232

test/MogenSwiftTest/MogenSwiftTest/MogenSwiftTest/_UnorderedToManySrcMO.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class _UnorderedToManySrcMO: NSManagedObject {
2626

2727
/// pragma mark - Life cycle methods
2828

29-
init(entity: NSEntityDescription!, insertIntoManagedObjectContext context: NSManagedObjectContext!) {
29+
override init(entity: NSEntityDescription, insertIntoManagedObjectContext context: NSManagedObjectContext?) {
3030
super.init(entity: entity, insertIntoManagedObjectContext: context)
3131
}
3232

@@ -61,32 +61,32 @@ class _UnorderedToManySrcMO: NSManagedObject {
6161
}
6262

6363
class func fetchAllUnorderedToManySrcs(managedObjectContext: NSManagedObjectContext!, error outError: NSErrorPointer) -> [AnyObject] {
64-
let model = managedObjectContext.persistentStoreCoordinator.managedObjectModel
64+
let model = managedObjectContext.persistentStoreCoordinator!.managedObjectModel
6565
let substitutionVariables = [:]
6666

67-
let fetchRequest = model.fetchRequestFromTemplateWithName("allUnorderedToManySrcs", substitutionVariables: substitutionVariables)
67+
let fetchRequest = model.fetchRequestFromTemplateWithName("allUnorderedToManySrcs", substitutionVariables: substitutionVariables as [NSObject : AnyObject])
6868
assert(fetchRequest != nil, "Can't find fetch request named \"allUnorderedToManySrcs\".")
6969

7070
var error: NSError? = nil
71-
let results = managedObjectContext.executeFetchRequest(fetchRequest, error: &error)
71+
let results = managedObjectContext.executeFetchRequest(fetchRequest!, error: &error)
7272

73-
if error {
73+
if (error != nil) {
7474
outError.memory = error
7575
}
7676

77-
return results
77+
return results!
7878
}
7979

8080
}
8181

8282
extension _UnorderedToManySrcMO {
8383

8484
func addRelationship(objects: NSSet) {
85-
self.relationshipSet().unionSet(objects)
85+
self.relationshipSet().unionSet(objects as Set<NSObject>)
8686
}
8787

8888
func removeRelationship(objects: NSSet) {
89-
self.relationshipSet().minusSet(objects)
89+
self.relationshipSet().minusSet(objects as Set<NSObject>)
9090
}
9191

9292
func addRelationshipObject(value: UnorderedToManyDstMO!) {

test/MogenSwiftTest/MogenSwiftTest/main.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
import Cocoa
1010

11-
NSApplicationMain(C_ARGC, C_ARGV)
11+
NSApplicationMain(Process.argc, Process.unsafeArgv)

test/MogenSwiftTest/MogenSwiftTestTests/MogenSwiftTestTests.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import MogenSwiftTest
44

55
class MogenSwiftTestTests: XCTestCase {
66
func newMoc() -> (NSManagedObjectContext) {
7-
let momURL : NSURL = NSBundle.mainBundle().URLForResource("MogenSwiftTest", withExtension: "momd")
8-
let mom : NSManagedObjectModel = NSManagedObjectModel(contentsOfURL: momURL)
7+
let momURL : NSURL = NSBundle.mainBundle().URLForResource("MogenSwiftTest", withExtension: "momd")!
8+
let mom : NSManagedObjectModel = NSManagedObjectModel(contentsOfURL: momURL)!
99
let psc : NSPersistentStoreCoordinator = NSPersistentStoreCoordinator(managedObjectModel: mom);
1010
let ps : NSPersistentStore = psc.addPersistentStoreWithType(
1111
NSInMemoryStoreType,
1212
configuration: nil,
1313
URL: nil,
1414
options: nil,
15-
error: nil)
15+
error: nil)!
1616
let moc : NSManagedObjectContext = NSManagedObjectContext()
1717
moc.persistentStoreCoordinator = psc
1818
return moc
@@ -87,7 +87,7 @@ class MogenSwiftTestTests: XCTestCase {
8787

8888
extension NSEntityDescription {
8989
class func entityForName_workaround(entityName: String!, inManagedObjectContext context: NSManagedObjectContext!) -> NSEntityDescription! {
90-
let entities = context.persistentStoreCoordinator.managedObjectModel.entitiesByName;
90+
let entities = context.persistentStoreCoordinator!.managedObjectModel.entitiesByName;
9191
let keys = Array(entities.keys)
9292
var result : NSEntityDescription?
9393
for (key, value) in entities {

0 commit comments

Comments
 (0)