Question: I am using [this](https://valor-software.com/ngx-bootstrap/#/typeahead) link for implementing a Typeahead. Now I am using TypeaheadOptionField to display a name on typeahead but it also binds the name string in the model. I want to bind the Object instead of the string.

My HTML Code:

```
<input formControlName="item"  class="form-control" [typeahead]="allItemsArray" [typeaheadItemTemplate]="customItemTemplate"
          [typeaheadOptionsLimit]="7" [typeaheadMinLength]="0" [typeaheadOptionField]="name" (typeaheadOnSelect)="onSelectItem($event)">

```

allItemsArray:

```
[
    {
        name: 'a',
        code: '12'
    },
    {
        name: 'b',
        code: '13'
    }
]

Value bound to form control: 'a'
Required value: {'name': 'a', 'code': '12'}

```

One thing I tried is implementing an event which sets the model value as object but it didn't work.

Answer: 
Update Object to core data

```
@IBAction func buttonUpdate(_ sender: Any) {
        let entity = NSEntityDescription.entity(forEntityName: "Students", in: managedContext)
        let request = NSFetchRequest<NSFetchRequestResult>()
        request.entity = entity
        let newName = UserDefaults.standard.value(forKey: "new") as! String
        let predicate = NSPredicate(format: "(name = %@)", newName)
        request.predicate = predicate
        do {
            let results =
                try managedContext.fetch(request)
            let objectUpdate = results[0] as! NSManagedObject
            objectUpdate.setValue(txtName.text!, forKey: "name")
            objectUpdate.setValue(txtPhone.text!, forKey: "phone")
            objectUpdate.setValue(txt_Address.text!, forKey: "address")
            do {
                try managedContext.save()
                labelStatus.text = "Updated"
            }catch let error as NSError {
              labelStatus.text = error.localizedFailureReason
            }
        }
        catch let error as NSError {
            labelStatus.text = error.localizedFailureReason
        }

    }

```
You need to set `NSNumber` instead of `String`. Replace this line:

```
object.setValue("\(jobId)", forKey: "jobId")

```

with:

```
object.jobId = jobId

```