make bool Optional core data

i have coredata and i want to add bool Optional but i get error:

import CoreData

@objc(HistoryData)

class HistoryData: NSManagedObject {
   
  @NSManaged var firstName: String
  @NSManaged var lastName: String
  @NSManaged var telephone: String
  @NSManaged var time: String
  @NSManaged var callHidden: Bool? // Here the error
}

Error:

Property cannot be marked @NSManaged because its type cannot be represented in Objective-C

in xcdatamodeld it selected Optional but it not do it..

why?

You should find the answer here : https://stackoverflow.com/questions/30722448/how-to-represent-an-optional-bool-bool-in-objective-c

So you have three choices:
- Take away the @objc that exposes all this to Objective-C
- Remove the Optional and just declare that type a Bool
- Use an object type. For example, declare the type as AnyObject? (or NSNumber?). This will work because Swift will bridge a Bool to an NSNumber (including as it passes into an AnyObject), and Objective-C will deal just fine with an Optional AnyObject or Optional NSNumber because those are object types, not scalars.

If you are using swift, can't you do this in an extension? like this? I haven't tried it.

=========================== extension HistoryData {

   var callHidden : Bool? {         get { return callHidden ?? false}

        set { callHidden = newValue }

===============================

If you are using swift, can't you do this in an extension? like this? I haven't tried it.

===========================

extension HistoryData {

   var callHidden : Bool? {

        get { return callHidden ?? false}

        set { callHidden = newValue }

===============================

make bool Optional core data
 
 
Q