1

I write application which get list last name and surname i use RestKit and MLPAutoCompleteTextField when write last name don't show autocomplete text

  var listDoctors = [String]()

    func autoCompleteTextField(textField: MLPAutoCompleteTextField!, possibleCompletionsForString string: String!, completionHandler handler: ([AnyObject]!) -> ()) {


        let appDelegate: AppDelegate = (UIApplication.sharedApplication().delegate as! AppDelegate)
        var requestParameters: [NSObject:AnyObject] = [NSObject: AnyObject]()

        requestParameters["name"] = textField.text

        appDelegate.objectManager.getObjectsAtPath("/doctors", parameters: requestParameters, success: {
            (rkoperation: RKObjectRequestOperation!, rkmap: RKMappingResult!) -> Void in

            if let doctors = rkmap.array() as? [Doctor] {
                for doctor: Doctor in doctors {

                    let nameDoctors = doctor.firstname
                    let lastnameDoctors = doctor.lastname
                    let list = nameDoctors + lastnameDoctors
                    self.listDoctors.append(list)

                }
            }

            handler(self.listDoctors)
            }, failure: {
                (rkoperation: RKObjectRequestOperation!, error: NSError!) -> Void in
                print("Load filed with error: @", error!)
                self.performSelectorOnMainThread(#selector(AppDelegate.showFetchError), withObject: nil, waitUntilDone: true)
        })
    }
}
Swift Developer
  • 247
  • 2
  • 18
  • Make it more clear – Shubham Jun 03 '16 at 09:51
  • @Shubham I don't undersand what write – Magdalena Dziesińska Jun 03 '16 at 09:53
  • Can you add `print(doctors)` before the `for` loop and add the printed text to your question? I'm suspecting that your code is fine and you're nog actually receiving any doctors. – SpacyRicochet Jun 03 '16 at 13:14
  • As an aside, using your `AppDelegate` in the way you're doing here is a very bad practice. If you're sure you need to use a singleton for your objectManager, take a look at this http://stackoverflow.com/a/24147830/571461. BUT, also read why singletons might be a bad choice here: http://stackoverflow.com/q/137975/571461. And using AppDelegate for `showFetchError` is a _very_ bad practice. Do that from the view controller. – SpacyRicochet Jun 03 '16 at 13:17

0 Answers0