2
0
MasterPassword/MasterPassword/ObjC/MPAppDelegate_Shared.m

51 lines
1.2 KiB
Mathematica
Raw Normal View History

//
// 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 {
2012-06-08 21:46:13 +00:00
#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)
2013-04-20 18:11:19 +00:00
err(@"Failed to retrieve active user: %@", error);
return activeUser;
}
- (void)setActiveUser:(MPUserEntity *)activeUser {
_activeUserOID = activeUser.objectID;
}
@end