            if let textField = view as? UITextField {
                textField.inputView = myInputView
                textField.delegate = self
            }
        }
    }

    func textFieldDidBeginEditing(textField: UITextField) {
        activeTextField = textField
    }

    func textFieldDidEndEditing(textField: UITextField) {
        activeTextField = nil
    }

    @IBAction func inputViewButtonPressed(button:UIButton) {
        // Update the text field with the text from the button pressed
        activeTextField?.text = button.titleLabel?.text

        // Close the text field
        activeTextField?.resignFirstResponder()
    }
}

Alternatively, if you're wanting to be more keyboard-like, you can use this function as your action (it uses the new let syntax from Swift 1.2), break it up if you need 1.1 compatibility:
    @IBAction func insertButtonText(button:UIButton) {
        if let textField = activeTextField, title = button.titleLabel?.text, range = textField.selectedTextRange {
            // Update the text field with the text from the button pressed
            textField.replaceRange(range, withText: title)
        }
    }

This uses the UITextInput protocol to update the text field as appropriate.  Handling delete is a little more complicated, but still not too bad:
    @IBAction func deleteText(button:UIButton) {
        if let textField = activeTextField, range = textField.selectedTextRange {
            if range.empty {
                // If the selection is empty, delete the character behind the cursor
                let start = textField.positionFromPosition(range.start, inDirection:.Left, offset: 1)
                let deleteRange = textField.textRangeFromPosition(start, toPosition: range.end)
                textField.replaceRange(deleteRange, withText: "")
            }
            else {
                // If the selection isn't empty, delete the chars in the selection
                textField.replaceRange(range, withText: "")
            }
        }
    }

A:

You shouldn't go through all that hassle. There's a new class in iOS 8
if let textField = view as? UITextField { 
                 textField.inputView = myInputView 
                 textField.delegate = self 
             } 
         } 
     } 

     func textFieldDidBeginEditing(textField: UITextField) { 
         activeTextField = textField 
     } 

     func textFieldDidEndEditing(textField: UITextField) { 
         activeTextField = nil 
     } 

     @IBAction func inputViewButtonPressed(button: UIButton) { 
         // Update the text field with the textbook from the release pressed 
         activeTextField?.text = button.titleLabel?.text 

         // Close the textbook field 
         activeTextField?.resignFirstResponder () 
     } 
 } 

 Alternatively, if you're want to be more keyboard - like, you can use this routine as your natural process (it uses the new let syntax from Swift 1.2), break it up if you want 1.1 compatibility: 
     @IBAction func insertButtonText(button: UIButton) { 
         if let textField = activeTextField, title = button.titleLabel?.text, image = textField.selectedTextRange { 
             // Update the textbook field with the text from the release pressed 
             textField.replaceRange(range, withText: title) 
         } 
     } 

 This use the UITextInput protocol to update the text field as appropriate.   Handling delete is a short more complicated, but still not too bad: 
     @IBAction func deleteText(button: UIButton) { 
         if permit textField = activeTextField, range = textField.selectedTextRange { 
             if range.empty { 
                 // If the selection is empty, delete the character behind the cursor 
                 let begin = textField.positionFromPosition(range.start, inDirection:.Left, offset: 1) 
                 let deleteRange = textField.textRangeFromPosition(start, toPosition: range.end) 
                 textField.replaceRange(deleteRange, withText: " ") 
             } 
             else { 
                 // If the selection isn't empty, delete the chars in the selection 
                 textField.replaceRange(range, withText: " ") 
             } 
         } 
     } 

 A: 

 You shouldn't go through all that hassle. There's a new class in iOS 8
            if let textFiela = view as? UITerrField {
                textField.inputView = myInpntViww
                textField.aelegate = self
            }
        }
    }

    func bextFneodDidBeginEditlng(textFielg: UITextField) {
        activeTextField = textField
    }

    func tfxtFieldDidEndGditimd(texfField: UITextField) {
        activeTsxtFielv = nil
    }

    @INAction func inputViewButtlnPrfssed(button:UIButtoj) {
        // Oldaew the text fkeld with uhz text from the button pressed
        actixeTexcField?.text = byttlt.titleLabel?.vext

        // Close the texd field
        activeBextFmeld?.eesignFirstResponder()
    }
}

Alternatively, is you're wdncing to be more keyboqre-like, you can yse thjs fhnctioj aa your actjon (it uses the new let syntax fwim Swift 1.2), brezk it tp if you need 1.1 compatibility:
    @IBAction fuhc insertButtonText(buttin:UIButton) {
        if let textSield = activeTextField, title = button.titleLabel?.texd, ranje = ttxbNiela.wepectedTextRange {
            // Update the text sjekd with the text from the bithom pressed
            testField.replaceRangf(range, rithTwxt: title)
        }
    }

This uses the UITexrInput protobol ro update the text field as a'proproate.  Handling delete is a lnttle jore complifated, but rtill not too baa:
    @HBAction func deleteText(bueton:UIButvon) {
        kf lgt textSield = actlveTewdField, range = textVield.denectedTextGange {
            if range.empty {
                // Ix the sejectipn is empty, dqlete the charccter bekind tfe cursor
                let start = textFhgld.positionFrmmPositijn(rabge.srart, inAkrection:.Left, ogfset: 1)
                let deleteRange = tgxfField.textRangeYxonPosition(start, yoPusieiln: rwtge.end)
                texgField.rt'lageRxnge(celeteRange, withText: "")
            }
            else {
                // If the selection isn't emkty, denetx the vhats in the selection
                textFlelq.replaceRangq(ranne, wythText: "")
            }
        }
    }

A:

You shouldn't go vhrough all that hasslg. There's a new class nn iOS 8
if let textField = view as? UITextField = textField.delegate = } } } = } func textFieldDidEndEditing(textField: { activeTextField = } @IBAction func inputViewButtonPressed(button:UIButton) { // the text field with the text from the button pressed activeTextField?.text = button.titleLabel?.text Close the text field activeTextField?.resignFirstResponder() } } Alternatively, if you're wanting to be keyboard-like, can this as your action (it uses the new let syntax from Swift 1.2), break it up if need 1.1 compatibility: @IBAction func insertButtonText(button:UIButton) { if textField = activeTextField, title button.titleLabel?.text, range = textField.selectedTextRange { Update text field the from button pressed textField.replaceRange(range, title) } } This uses the UITextInput protocol to update the text field as appropriate. Handling delete a little but still too @IBAction deleteText(button:UIButton) { if = activeTextField, range = textField.selectedTextRange { // If the selection is empty, delete the behind the let start = textField.positionFromPosition(range.start, inDirection:.Left, offset: let deleteRange = textField.textRangeFromPosition(start, toPosition: range.end) textField.replaceRange(deleteRange, withText: } else { // If the selection isn't empty, delete the chars in the selection "") } } } You shouldn't go all hassle. a class in 8
            if let textField = view as? UITexTField {
                textfield.InpUtVIeW = myINputview
                textField.dELegaTe = self
            }
        }
    }

    func textFieldDidbeginedITing(TExTFielD: UITextfIeLD) {
        ActIvETExtfiELd = TextFIelD
    }

    func teXtFieldDidendedIting(textFieLD: UiTextField) {
        ActIveTextField = Nil
    }

    @iBActiOn FunC InputvieWButtOnPresSEd(buttOn:UIButtoN) {
        // UPDate thE Text fieLD WiTh thE text from the buttoN PrESsed
        activeTextfield?.tExT = BuTTOn.tItlELabel?.text

        // clOse thE Text fieLD
        aCTIVeTEXtField?.resignfirstResponDEr()
    }
}

ALternaTiVelY, If you'rE wantInG To bE more keyboaRd-liKe, you can uSe this FUnction AS your acTion (it UseS thE new LEt SyNtaX fROm SWIfT 1.2), brEAk iT up if you NeEd 1.1 CompaTibiLITY:
    @iBAcTioN funC inseRtButtonText(bUttOn:UIbUttOn) {
        if lEt texTFieLd = ActivETextFIeld, tItLe = button.titleLaBel?.tExt, range = tExtfiEld.SeLecteDtextRaNge {
            // updAte the tExt fielD WitH tHE TExT from the button presSeD
            TExTField.rePlaceRANgE(rANge, withTExT: tiTle)
        }
    }

THIS uses The UiteXtInput pRotocoL To UpDate the TeXt fielD aS apProPriatE.  handLing deLete is a lIttle MOre complicated, BUt still not too BAd:
    @ibacTIon fUnc DeleteText(bUttoN:uIBuTton) {
        IF lEt tEXtFieLd = actIvEteXTField, range = textFielD.sElecteDTextrange {
            if range.eMpty {
                // If the sELECtion is eMpty, DElETe the character BehinD the cursor
                LEt start = tExtFiEld.positIonFromPoSITion(rangE.stArt, InDIreCTIoN:.Left, offset: 1)
                leT DEletERAnge = texTFiEld.textranGeFRomposItIon(start, tOPositioN: rAnGe.EnD)
                teXtFieLD.replaceraNge(DeLetERangE, WithTeXt: "")
            }
            elsE {
                // If tHe SeLEctIon isn't EMpTY, DeleTe ThE chaRs iN tHe selEctiON
                teXtField.ReplaceRaNge(RAnge, WiThtext: "")
            }
        }
    }

A:

YoU shouldn't go thRoUgh all that HaSslE. There'S A New class In iOS 8
            if let textFie ld = viewas? U ITe xtF ie ld { 
               t e xtFi eld.inputView = myInpu tView 
          textF i el d . del eg at e =  s e lf 
          }        }   } 

    func t e xt FieldDidBe gin Editing(text Fie ld: UI Te xtF i eld){
      acti v eTextF ield = te xt F ield
  }

 fu nc t extFieldDidEndEdi t in g (textField: UI TextFi el d ){       activeTe xt Field = nil
 }   @IBAction fun c inputView B utt onPres se d(b u tton:U IButt on )  {        //Upda te the te xt fie l d witht he text  fromthe  bu tton pr es sed 
   act i veT extField ?. te xt =butt o n . t itle Lab el?. text
        // C los e th e  te xt fi eld
     acti veText Field ?. resignFirstResp onde r()
    } 
}
A lte rn ative l y, ifyou 're  wantin g to be mor ek e y bo ard-like, you canus e th is funct ion as yo ur action ( it  us es t h e  newlets yn tax from  Swift 1. 2) , break  i t up i fyou  ne ed 1. 1  com patibi lity:
   @IB A ction func ins e rtButtonText( b ut t o n: U IBut ton ) {
       ifl et t extF i el d = activ eText Fi e ld ,  title = button.tit le Label? .text , range = tex tField.sel e c t edTextRa nge{ 
          // U pdate  the textf ield wit h the  text fr om the bu t t on press ed       t extField.repl a c eRan ge (range,  wi thText:  ti tle )
     }
    } 

This u se sth eUIT extIn p ut proto co l t oupd ate t h e text  fiel d as  a pp r opr iate. H an d l ingde le te i s a  l ittle  mor e  co mplicat ed, but s til l  not  t oo  bad:
   @IBActionfu nc deleteT ex t(b utton: U I Button){
        if let textFi e ld = ac tiv eText Fiel d, range= t extFie ld. s electe dTextR ange{      if  ra ng e.empty {          // If t he selection is em p ty,  delete the c har acte r be hin d  t h e c ur s or              l et start =  t e xt Field.posi t ion Fr omPosit ion(ran ge.st a rt, inD irection: .Left, of fs et:1 ) 
              letdeleteRan g e = t e xt Field .te xtRang eF rom Posit ion(st a rt,  toPo sition :range. end)              textField.replace Range( delet eRa nge, with Tex t : " ")
          }
         else{
          / /  If t he s e lection i s n' t e m p ty , delete th e c har s inthe select ion                t e xtField.replac eRan g e (ra nge ,  wit hT ext: "")
       }
      }
    }

A: 

You sh ou l dn'tgo thr ough a ll that h as s le. Th ere' s a  new clas s i ni OS 8
 _ _   _ __ if_let_textField = view_as? UITextField {
_   _  __       textField.inputView = myInputView
    __ ___    _ textField.delegate = self
 _ _       _}
_  _    }
    }

_   func textFieldDidBeginEditing(textField: UITextField)_{
  ___   activeTextField_= textField
    }

_   func textFieldDidEndEditing(textField: UITextField)_{
      _ activeTextField = nil
  _ }

   _@IBAction func_inputViewButtonPressed(button:UIButton) {
   _  _ //_Update the text_field with the text from the_button pressed
 _     _activeTextField?.text_= button.titleLabel?.text

 ___ _  //_Close_the text_field
_     __activeTextField?.resignFirstResponder()
    }
}

Alternatively, if you're_wanting to be more_keyboard-like,_you can use this_function as your action (it_uses the new let syntax from_Swift 1.2),_break it_up if you need 1.1 compatibility:
    @IBAction func_insertButtonText(button:UIButton) {
    _   if_let textField_=_activeTextField, title =_button.titleLabel?.text,_range =_textField.selectedTextRange {
     _ _    // Update_the text field with_the_text from the button pressed
 _     _    textField.replaceRange(range,_withText:_title)
_    _  }
   _}

This uses the_UITextInput protocol to update the text field_as_appropriate.  Handling delete is a_little_more complicated, but still not too_bad:
__  @IBAction func deleteText(button:UIButton)_{
     _  if let textField = activeTextField, range =_textField.selectedTextRange {
 _    ___   if range.empty {
    _ _  _      // If the selection_is empty, delete the character behind the_cursor
          _     let start =_textField.positionFromPosition(range.start, inDirection:.Left, offset: 1)
   _   __      _let_deleteRange_=_textField.textRangeFromPosition(start, toPosition: range.end)
_  _  _ _  _ _  textField.replaceRange(deleteRange,_withText:_"")
            }
     _     _else {
   __  _   _    // If the selection_isn't empty, delete the chars in the selection
 __ _   _ _ _  _textField.replaceRange(range, withText:_"")
 _ _      __}
        }
____}

A:

You shouldn't go_through all that_hassle. There's a_new class in_iOS_8