0

I set about an attribute it is NOT optional, but still when read value of it, it returns an optional variable, why?

enter image description here enter image description here

János
  • 32,867
  • 38
  • 193
  • 353

1 Answers1

0

What you set in your model may not directly correspond to what you have in your code. Consider that the model will work for multiple platforms (iOS, OSX) and for multiple languages (Swift, Objective-C).

Your classes are then autogenerated where in your case it seems you are using Swift. But they are subclasses of managed objects which are NSObject subclasses so on bottom you are on objectiveC. If I remember correctly all of these properties will be force-unwrapped which still means they are wrapped ergo optional when printed.

ObjectiveC has a bit different system of constructors and at some point each of the values/properties in an object will be null. Due to how CoreData works it might make sense to keep force-unwrapped values.

So a long story short: These two may not be as tightly connected as you believe. But you should not worry about that, if this breaks any of your functionality/code you should ask the question directly.

Matic Oblak
  • 16,318
  • 3
  • 24
  • 43