You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
3.5 KiB

2 months ago
  1. //
  2. // AppDelegate.m
  3. // HC
  4. //
  5. // Created by huilinLi on 2025/11/17.
  6. //
  7. #import "AppDelegate.h"
  8. @interface AppDelegate ()
  9. @end
  10. @implementation AppDelegate
  11. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  12. // Override point for customization after application launch.
  13. return YES;
  14. }
  15. #pragma mark - UISceneSession lifecycle
  16. - (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {
  17. // Called when a new scene session is being created.
  18. // Use this method to select a configuration to create the new scene with.
  19. return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
  20. }
  21. - (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions {
  22. // Called when the user discards a scene session.
  23. // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
  24. // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
  25. }
  26. #pragma mark - Core Data stack
  27. @synthesize persistentContainer = _persistentContainer;
  28. - (NSPersistentContainer *)persistentContainer {
  29. // The persistent container for the application. This implementation creates and returns a container, having loaded the store for the application to it.
  30. @synchronized (self) {
  31. if (_persistentContainer == nil) {
  32. _persistentContainer = [[NSPersistentContainer alloc] initWithName:@"HC"];
  33. [_persistentContainer loadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription *storeDescription, NSError *error) {
  34. if (error != nil) {
  35. // Replace this implementation with code to handle the error appropriately.
  36. // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
  37. /*
  38. Typical reasons for an error here include:
  39. * The parent directory does not exist, cannot be created, or disallows writing.
  40. * The persistent store is not accessible, due to permissions or data protection when the device is locked.
  41. * The device is out of space.
  42. * The store could not be migrated to the current model version.
  43. Check the error message to determine what the actual problem was.
  44. */
  45. NSLog(@"Unresolved error %@, %@", error, error.userInfo);
  46. abort();
  47. }
  48. }];
  49. }
  50. }
  51. return _persistentContainer;
  52. }
  53. #pragma mark - Core Data Saving support
  54. - (void)saveContext {
  55. NSManagedObjectContext *context = self.persistentContainer.viewContext;
  56. NSError *error = nil;
  57. if ([context hasChanges] && ![context save:&error]) {
  58. // Replace this implementation with code to handle the error appropriately.
  59. // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
  60. NSLog(@"Unresolved error %@, %@", error, error.userInfo);
  61. abort();
  62. }
  63. }
  64. @end