CKRecordValue type NSDate stores nil value?

In the development of an app, one of its UITextField is designed to allow users to use input view of datePicker view to pick a date and also allows the users to delete a displayed date via clear button as a overlay view in the textField while edting. Data is stored via Cloudkit and a CKRecordValue type - NSDate is used for that UITextField.


My question is how to change the NSDate to reflect the user deleting an existing date on the textField? It seems NSDate can't be nil as I got atomic error when trying to save a nil date. Direct database like MySQL gives an option of null value and I wonder if we may set a NSDate type to allow nil input?

>It seems NSDate can't be nil as I got atomic error when trying to save a nil date


Rather than use nil, use your favorite date in the past. If the viewController detects that the use has tapped the clear button then set the date to that favorite date.

Great point which definitely walkarounds the empty or nil date issue. However it may increase the complexity of coding as I have to deal with NS Date field value differrently from other CKRecordValue types which may store empty value of that type via Cloudkit.


Why can Apple redesign their API for Cloudkit to implement the similar walkaround? It's very common usage - any data can be optional including date input and I bet their underlying database schema can be set to use optional null/nil.


If their API mandate is to provide easy-to-use Cloudkit usage for developer, I truely hope they may take the initiative to make the change.

So for a column that represents NSDate, it is considered nonnull and you have to use a placeholder date value instead? Is there any particular reason why you can't set a date nil?

Just discovered that... We can not have a nil NSDate field in CloudKit, when I save a record it is set to a default date 2001,01,01 but it is not nil.

I do not want to add a boolean column or a "placeholder" value to know if the date is nil or not + always think about it otherwise I will have incorrect data shown to the user.

Is there something we can do ? Does someone has an answer? I miss something I think as I can not find many resources on this BIG disadvantage to use CloudKit!

CKRecordValue type NSDate stores nil value?
 
 
Q