2
0
MasterPassword/MasterPassword/ObjC/MPAppDelegate_Shared.m
Maarten Billemont d27a0fdbad Core Data context fixes and migration fixes.
[FIXED]     More careful Core Data threading and context usage.
[FIXED]     iOS bug when migrating, now using USM's copy migration.
[ADDED]     Better handling of store changes while in Main VC and Element List VCs.
2013-04-28 00:35:32 -04:00

51 lines
1.2 KiB
Objective-C

//
// MPAppDelegate.m
// MasterPassword
//
// Created by Maarten Billemont on 24/11/11.
// Copyright (c) 2011 Lyndir. All rights reserved.
//
#import "MPAppDelegate_Shared.h"
#import "MPAppDelegate_Store.h"
@implementation MPAppDelegate_Shared {
NSManagedObjectID *_activeUserOID;
}
+ (MPAppDelegate_Shared *)get {
#if TARGET_OS_IPHONE
return (MPAppDelegate_Shared *)[UIApplication sharedApplication].delegate;
#elif defined (__MAC_OS_X_VERSION_MIN_REQUIRED)
return (MPAppDelegate_Shared *)[NSApplication sharedApplication].delegate;
#else
#error Unsupported OS.
#endif
}
- (MPUserEntity *)activeUserForThread {
return [self activeUserInContext:[MPAppDelegate_Shared managedObjectContextForThreadIfReady]];
}
- (MPUserEntity *)activeUserInContext:(NSManagedObjectContext *)moc {
if (!_activeUserOID || !moc)
return nil;
NSError *error;
MPUserEntity *activeUser = (MPUserEntity *)[moc existingObjectWithID:_activeUserOID error:&error];
if (!activeUser)
err(@"Failed to retrieve active user: %@", error);
return activeUser;
}
- (void)setActiveUser:(MPUserEntity *)activeUser {
_activeUserOID = activeUser.objectID;
}
@end