It's hard to believe, but when using the run argument "-com.apple.CoreData.ConcurrencyDebug 1", the app would crash consistently just because its name (PRODUCT_NAME variable in Xcode build settings) starts with "Music" or "Musik". Simply changing the target name prevents the crash.
This issue started appearing only on iOS 14.0
To reproduce:
Use Xcode 12.01 to create a new project -> iOS -> App. Use Core Data and Objective-c in the wizard settings.
This issue started appearing only on iOS 14.0
To reproduce:
Use Xcode 12.01 to create a new project -> iOS -> App. Use Core Data and Objective-c in the wizard settings.
Enter an app name which is starting with "Music" or "Musik". For example "MusicTest".
Place "-com.apple.CoreData.ConcurrencyDebug 1" in the scheme run arguments.
Add a new entity to the data model named "TestEnt"
Add the following code to the end of the AppDelegate.m file.
Code Block - (void)test { // --- // Set run argument in the scheme as follow: // -com.apple.CoreData.ConcurrencyDebug 1 // --- NSLog(@"TEST"); dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{ NSManagedObjectContext *managedObjectContext = [self managedObjectContext]; [managedObjectContext performBlockAndWait:^{ NSError *error = nil; NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"TestEnt"]; NSArray *result = [managedObjectContext executeFetchRequest:request error:&error]; NSLog(@"result=%@", result); }]; }); } - (NSManagedObjectContext *)managedObjectContext { // The old-fashion way to create a managed object conttext NSString *documentsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; NSString *storeFilePath = [[documentsDir stringByAppendingPathComponent:@"MusicTest"] stringByAppendingPathExtension:@"sqlite"]; NSURL *storeURL = [NSURL fileURLWithPath:storeFilePath]; NSURL *objectModelURL = [[NSBundle mainBundle] URLForResource:@"MusicTest" withExtension:@"momd"]; NSManagedObjectModel *objectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:objectModelURL]; NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:objectModel]; NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption: @YES, NSInferMappingModelAutomaticallyOption: @YES}; NSError *error = nil; [coordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]; NSManagedObjectContext *managedObjectContext = nil; if (coordinator != nil) { managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; managedObjectContext.persistentStoreCoordinator = coordinator; managedObjectContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy; } return managedObjectContext; }
Modify code on ViewController.m as follow:
Code Block - (void)viewDidLoad { [super viewDidLoad]; [(AppDelegate *)UIApplication.sharedApplication.delegate test]; }
Run project and view crash coming.
Code Block Multithreading_Violation_AllThatIsLeftToUsIsHonor
Select MusicTest project on the project navigator.
Rename "MusicTest" appearing under "TARGETS" on the main window to "MyMusicTest"
Run project again
No crash this time.