【发布时间】:2014-07-17 22:20:11
【问题描述】:
我制作了一个简单的应用程序,用于在 CoreData 中使用 CoreLocation 存储位置。我的问题是现在我想通过电子邮件发送我所有的“数据库”(CoreData)来查看和处理数据,但我做不到。我试图将 NSManagedObjects 转换为 NSDictionary 并枚举该字典,但它总是为空。我该怎么办?
- (NSManagedObjectContext *)managedObjectContext
{
NSManagedObjectContext *context = nil;
id delegate = [[UIApplication sharedApplication] delegate];
if ([delegate performSelector:@selector(managedObjectContext)]) {
context = [delegate managedObjectContext];
}
return context;
}
NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"RegistoCoreData"];
self.locations = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];
[self.tableView reloadData];
- (IBAction)send:(id)sender {
NSArray *keys = [[[location entity]attributesByName]allKeys];
dicionarioLocalizacoesNoCoreData = [location dictionaryWithValuesForKeys:keys];
for (NSString *valores in dicionarioLocalizacoesNoCoreData){
NSLog(@"%@, %@", valores, [dicionarioLocalizacoesNoCoreData objectForKey:valores]);
}
// Email Subject
NSString *emailTitle = @"Localizações";
// Email Content
NSString *messageBody = [NSString stringWithFormat:@"%@, %@",valores, [dicionarioLocalizacoesNoCoreData objectForKey:valores]];
// To address
NSArray *toRecipents = @[@"email@mail.com"];
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:messageBody isHTML:NO];
[mc setToRecipients:toRecipents];
// Present mail view controller on screen
[self presentViewController:mc animated:YES completion:NULL];
}
【问题讨论】:
-
"...我想通过电子邮件发送我所有的“数据库”(CoreData) 以查看和处理数据..." 所以这只是为了您自己使用,检查和编辑数据?或者它是完成后将在应用程序中的一项功能?
-
仅供我自己使用是的
标签: core-data core-data-migration