0

I am using CoreData in SwiftUI for MacOS. I am using Binary Data inside an entity in CoreData to store my images.

Everything is working fine.. this attribute should be optional and it is marked as optional. When I wanna use that Data, I always check first if it is not nil and then use it.

If it is nil I want to display a default image. That is working totally fine.

Nevertheless, SwiftUI always gives me an error message when comparing that value with nil.

Image is my BinaryData attribute at person.

This line:

if (person.image != nil)

... causes that error message.

Comparing non-optional value of type 'NSData' to 'nil' always returns true

I understand the message, but I want it to have it as optional. And the comparison it still working, even though it should always return true.

enter image description here

davidev
  • 7,694
  • 5
  • 21
  • 56

0 Answers0