Skip to content
PickerFieldsDataHelper is a protocol in Swift, that helps using selectable options in text field outlets.
Swift Ruby
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.

PickerFields Data Helper

Swift (+3.0) Protocol to create Picker Views and Date Pickers to work with Text Fields' outlets, providing selectable options to fulfill them.

Version License Platform

storyboard storyboard

Try it!

pod try PickerFieldsDataHelper


Just add the file 'PickerFieldsDataHelper.swift' to your project.


class ViewController: UITableViewController, PickerFieldsDataHelperDelegate {

    let pickerFields = PickerFieldsDataHelper()

    override func viewDidLoad() {
        pickerFields.delegate = self



		//... (viewDidLoad method)

        //Setting up simple pickers with options for each text field
        pickerFields.addDataHelpers([accountTypeTextField, profileVisibilityTextField])
        //Setting up date Type field
        pickerFields.addDataHelper(birthDateTextField, isDateType: true)

Adding Data

You can add objects with representing titles to each field at any moment. Picker data are refreshed automatically.

    func loadAccountTypeOptions() {
        pickerFields.addTitleAndObjectInDataHelper(accountTypeTextField, title: "Normal User", object: 0)
        pickerFields.addTitleAndObjectInDataHelper(accountTypeTextField, title: "Admin", object: 1)
    func loadProfileVisibilityOptions() {
        pickerFields.addTitleAndObjectInDataHelper(profileVisibilityTextField, title: "Private", object: "PRI")

        //Add an option to be default - starts with the option selected.
        pickerFields.addTitleAndObjectInDataHelper(profileVisibilityTextField, title: "Public", object: "PUB", isDefault: true)

Getting Data

Use 'selectedObjectForTextField' method to get the current object for the selected option.

It can be nil if there is an non-value option selected like "Select an option".

    if let object = pickerFields.selectedObjectForTextField(accountTypeTextField) {
    	//Use object
	} else {
		//No valid option selected


Select Confirmation Button

        pickerFields.doneButtonTitle = "Choose"
        pickerFields.needsConfirmationButton = false //Selects without tapping the button

Non-value Default Option

        pickerFields.useDefaultFirstItem = true
        pickerFields.defaultFirstItemTitle = "Select an option"
        pickerFields.initWithDefaultFirstItemSelected = false //Start fields with "Select an option" text

Date Type: Start with today's date

		pickerFields.initWithTodayDate = true

Clearing Fields

When calling 'clearAllFields()', all fields turn to default state.

    @IBAction func clearAllFields(sender: AnyObject) {

Optional Methods

Get title and object when selecting an item.

    func pickerFieldsDataHelper(dataHelper: PickerDataHelper, didSelectObject selectedObject: AnyObject?, withTitle title: String?) {
        //Use 'title' or 'selectedObject'.


To run the example project, clone the repo, and run pod install from the Example directory first.


PickerFieldsDataHelper is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'PickerFieldsDataHelper'


Allan Alves,


PickerFieldsDataHelper is available under the MIT license. See the LICENSE file for more info.

You can’t perform that action at this time.