Search code examples
iosswiftcore-datauipickerview

how to store uibutton value in database?


I have one UIPickerView and when user click on UIButton then UIPickerView will appear and user select value from UIPickerView and this value display on UIButton. i want to store UIButton value in core database for iOS swift application.


Solution

  • Don't store the value in a button. Buttons are view objects, not model objects. Saving state data to a view object violates the MVC design pattern.

    In your picker view code, both store the value in a property of your view controller and display it to you button.

    Then you can write code to save your property value to core data as needed.