0

Periodically I launch my app from Xcode to find Core Data errors due to an empty model file. The versioned model files are found in the main bundle but the model file still inits to nil. See my answer for partial workarounds but no solution to date.

I've verified that the files exist and are accessible using the access function. I've tried using initWithContentsOfURL and mergedModelFromBundles with the same result.

This happens randomly and I suspect something is changing the model file behind the scenes but I don't know what.

greg
  • 1,926
  • 17
  • 26
  • This could be a hardware issue, e.g. limited space, failing drive, cable or connections. – mikeD Dec 25 '14 at 17:48
  • Interesting idea. I can verify that space is not a factor. It's a MacBook Pro that I use day in and out, and can't point to any regularity that would've made me think that would be a problem. I'll keep an eye on things with that in mind though. – greg Dec 26 '14 at 00:51
  • This happened again today and I've discovered that my app can't access any files in its bundle. All checks to fileExistsAtPath return NO and trying to enumerate directory contents fails with error -260 claiming that the directories don't exist. Cleaning the project has no affect, neither does deleting all files in DerivedData. – greg Jan 09 '15 at 22:06

1 Answers1

1

Restarting my computer seems to have solved the security related crash but this also necessitates removing the existing Core Data store file as it complains the existing one doesn't match the model file.

[UPDATE]

Restarting does not solve the problem. But reseting the current version of the Core Data model file did the trick. I changed it to an older version and then back. This question helped me think of this as something to try. Using mergedModelFromBundles: and versioning (CoreData) Still not sure what the root problem is.

[ANOTHER UPDATE]

I put a file monitor on the .xccurrentversion file in my Core Data momd file bundle to observe when the file is being touched. I've noticed that XCode (or some build tool) updates the .xccurrentversion file periodically when XCode comes to foreground (either when the project is opened or when it's been in background for a while). When it did this today it updated the file setting _XCCurrentVersionName to the main momd file bundle rather than the version file. I replaced the .xccurrentversion file with an older version and it launched. This would explain why reseting the current model version fixes this issue. I have no idea what the conditions are for XCode to update this file.

Community
  • 1
  • 1
greg
  • 1,926
  • 17
  • 26