3 Replies
      Latest reply on Oct 11, 2019 7:21 AM by Macho Man Randy Savage
      Ron from Ottawa Level 1 Level 1 (0 points)

        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?

        • Re: CKRecordValue type NSDate stores nil value?
          PBK Level 7 Level 7 (3,265 points)

          >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. 

            • Re: CKRecordValue type NSDate stores nil value?
              Ron from Ottawa Level 1 Level 1 (0 points)

              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.