Xcode Crash due to Persistance container in swift - ios

I'm currently making an app implementing core data. However, when I build, it crashes at this line:
Thread 1: Fatal error: Unresolved error Error
Domain=NSCocoaErrorDomain Code=134140 "Persistent store migration
failed, missing mapping model."
UserInfo={sourceModel=() isEditable
0, entities {
What does this mean? How can I solve this?

Related

NSPersistentCloudKitContainer error handling

Sometimes an NSPersistentCloudKitContainer will report an error in the console like so:
*2020-04-14 16:41:27.725794+0100 ExampleApp[9736:8226377] [error] error: CoreData+CloudKit: -: <NSCloudKitMirroringDelegate: 0x282b944d0>: Sending ‘NSCloudKitMirroringDelegateWillResetSyncNotificationName’ with reason: ‘UserPurgedZone’* [NSCloudKitMirroringDelegate logResetSyncNotification:](1798)
In my code I have error handling in the loading of the persistent store but this error doesn't trigger it as this error comes after the store has loaded.
Where do I handle these errors? How can I see these errors in code?

CoreData Error: Invalid generation token: this persistent store coordinator does not have any of the referenced stores

I'm unable to repro this error but my crash reporter indicates that it's fairly frequent among my users (iOS 12):
Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=134060 "A Core Data error occurred." UserInfo={Reason=Invalid generation token: this persistent store coordinator does not have any of the referenced stores}: file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang_Fall2018/swiftlang_Fall2018-1000.11.42/src/swift/stdlib/public/core/ErrorType.swift, line 184
Crashing line example:
let result = try! self.syncContext.fetch(request)
I would like to decipher error message. Does Invalid generation token refers to NSQueryGenerationToken? Is the error part of conflict resolution process?

UIDocument save error: Could not get attribute values

I see this error in Xcode debug console when I call save(...) on my UIDocument, but it seems to have no effect on my app. Anyone know what causes it and how to stop it? I'm saving documents as a package with FileWrapper.
2018-08-12 10:24:12.818324-0400 MyApp[2694:1486251] [default] [ERROR]
Could not get attribute values for item /private/var/[...]/Documents/NewDoc.myextension (s).
Error: Error Domain=LocalStorageFileProvider.LocalFileProviderError Code=0 "(null)"

Failure to save data to HealthKit (Cocoa error 4097)

I'm currently having difficulty saving data to health kit and I'm unsure what the problem is. I have health kit enabled and have granted read and write permissions on my testing device when the app runs (everything looks OK and I'm able to query the health kit database without error). I'm using Swift.
The code I'm using to save is:
hksaver.healthStore!.saveObjects(samples, withCompletion: {
(success: Bool , error: NSError!) -> Void in
if success { ... } else {
println("Failed to save. Error: \(error)")
}
samples is an array of HKQuantity Samples. It is created by appending 'dataSample' as defined below:
let dataPoint = HKQuantity(unit: units, doubleValue: measurement.dataPoint)
let dataSample = HKQuantitySample(type: quantityType,
quantity: dataPoint, startDate: measurement.startDate,
endDate: measurement.endDate, metadata: metadata)
There are no errors when constructing this, so I believe that all the values are appropriate.
When I run, I'm getting the following error:
Failed to save. Error: Error Domain=NSCocoaErrorDomain Code=4097 "The
operation couldn’t be completed. (Cocoa error 4097.)" (connection to
service named com.apple.healthd.server) UserInfo=0x17047a0c0
{NSDebugDescription=connection to service named
com.apple.healthd.server}
I'm trying to write ~100,000 values to HealthKit though I haven't been able to find any limits (the same error occurred when I was trying to write ~50,000 values). I've tried to write this in chunks, but after around 5 calls to health kit it starts failing (I'm assuming there is a limit to prevent continuous calls although I haven't seen anything in any documentation I've looked at).
I've tried searching under the error code, under the entire error, and under everything I could think of to explain the problem. The only results I've returned deal with HomeKit and tend to be that it is not activated. However under the capabilities tab I have HealthKit turned on and everything is check marked so I don't think that is the problem.
Any thoughts would be appreciated!

iCloud fails with core data - partial updates - undocumented error message

I am trying to sync the data of a core data app between two devices via iCloud. It basically seems to work, but it mostly fails. Data does not show up, or shows up randomly / partially. Sync takes forever (sometimes: hours).
Of course I tried all obvious remedies such as deleting the apps and data from the devices etc.
I get the following messages (relevant excerpt):
[_PFUbiquityRecordsImporter operation:failedWithError:](839):
CoreData: Ubiquity: Import operation encountered an error:
Error Domain=NSCocoaErrorDomain
Code=134060 "The operation couldn’t be completed.
(Cocoa error 134060.)" UserInfo=0x1106a6a0
{exception=Attempted to perform an operation without an open database}
while trying to import the log file at the URL:
<PFUbiquityTransactionLog: 0x11062710>
right after
CoreData: Ubiquity: Error importing transaction log:
<PFUbiquityTransactionLog: 0x110eb820>
and later
-[_PFUbiquityRecordsImporter operation:failedWithError:](824):
CoreData: Ubiquity: Import operation encountered a corrupt log file,
Error Domain=NSCocoaErrorDomain Code=134302
"The operation couldn’t be completed. (Cocoa error 134302.)"
UserInfo=0x12e0b0 {underlyingError=Error Domain=NSCocoaErrorDomain Code=19
"The operation couldn’t be completed. (Cocoa error 19.)" UserInfo=0x1af070
{NSUnderlyingException=error during SQL execution : constraint failed,
NSFilePath=/var/mobile/Applications/
59087988-334C-40DC-9F6A-C7DA22F7B790/Documents/database.sqlite,
NSSQLiteErrorDomain=19}, reason=Error encountered while importing
transaction log at URL: <PFUbiquityTransactionLog: 0xe87b3f0>
Any clues about this "without an open database" error?
What to do about the "corrupt log file"?

Resources