【发布时间】:2011-05-13 09:04:35
【问题描述】:
我可能在标题中使用单例一词时的术语不正确。 我现在正在寻找一种好的技术。我有一个名为 user 的实体,它存储用户登录的数据,例如用于发出服务器请求的会话密钥。我只希望这些实体中的一个永远存在。是否有执行此操作的标准技术?
我目前的情况是这样的
NSManagedObjectContext *moc = [self managedObjectContext];
NSEntityDescription *entityDescription = [NSEntityDescription
entityForName:@"UserEntity" inManagedObjectContext:moc];
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
[request setEntity:entityDescription];
NSArray *array = [moc executeFetchRequest:request error:&error];
if (array == nil)
{
// Deal with error...
}
if ([array count]==0) {
//first run of app
}else if([array count]==1)
{
// id like the code to enter here after every app run except for the first one
}else
{
//dont want this to happen
}
【问题讨论】:
标签: iphone cocoa-touch core-data