1
let a = attachment.localPath
DispatchQueue.main.async {
    let b = attachment.localPath
}

If I'd print those with the debugger, the value of a is a valid path, while the value of b is nil.

The value for attachment.localPath was edited before this code runs, and all contexts were saved.

This only happens if I build my app on Xcode 10 and run it on iOS 13. If I run it on iOS 12 everything goes well. If I build on Xcode 11 and run on iOS 13, everything's fine as well.

The variable attachment is a managed object, that contains an attachment card (another managed object), that has the attribute localPath. The getter for localPath in the attachment object just returns the value of attachmentCard.localPath.

I've tried the same with another attribute from attachmentCard and it works fine, both a and b get the correct value.

I've placed a breakpoint on the setter for localPath, and nothing sets it to nil.

What could be happening here?

pepsy
  • 1,437
  • 12
  • 13
  • It says in documentation not to pass managed objects across threads. You should pass Managed Object ID's. Then the destination thread will pull the full object based on the Managed Object ID https://cocoacasts.com/three-common-core-data-mistakes-to-avoid – Loren Rogers Aug 30 '19 at 19:55
  • @LorenRogers I'm not changing threads, this entire piece of code is run on the main thread. If I change the implementation to use attachment's moc to run the async code and get the object from the moc using the attachment's objectID, the problem persists. – pepsy Aug 30 '19 at 20:07

0 Answers0