0

:I have problem. I create list doctor show firstname and lastname. How objects to the listdoctor

 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
    // Wykonanie żądania
    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 {
                // show error Experession resolves to an unused I-value
                doctor.firstname
                self.listDoctors.append(doctor.firstname)
            }
        }
        }, failure: {
            (rkoperation: RKObjectRequestOperation!, error: NSError!) -> Void in
            print("Load filed with error: @", error!)
            self.performSelectorOnMainThread(#selector(AppDelegate.showFetchError), withObject: nil, waitUntilDone: true)
    })
    handler(listDoctors)
2
  • not sure why you are compiling a list from the the response when you are using RestKit. Once the RestKit request is finished you should query CoreData for your list of doctors Commented Jun 2, 2016 at 10:42
  • i must show list name and surname on UITextField Commented Jun 2, 2016 at 10:54

3 Answers 3

1
   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
        // Wykonanie żądania
        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 {
                    var nameDoctoers = doctor.firstname

                    self.listDoctors.append(nameDoctors)
                }
            }
            }, failure: {
                (rkoperation: RKObjectRequestOperation!, error: NSError!) -> Void in
                print("Load filed with error: @", error!)
                self.performSelectorOnMainThread(#selector(AppDelegate.showFetchError), withObject: nil, waitUntilDone: true)
        })
        handler(listDoctors)
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

You should create String array.

    //Array with dummy names
    var nameArray = ["Red","Raain","Rozi","Rozina","Rozinava", "Roy","Roy son","Rediss","Raj","Blue", "Yellow"]

    //Get name from the Doctor object
    var name = doctor.firstname
    name = ((name ?? "").isEmpty ? "" : name!)//if string is empty return default value
    print("name is \(name)")

    //append to array
    self.nameArray.append(name!)

    print("names are \(nameArray)")

Comments

0

I correct my code now I add lastname arry listDoctors should be return name and lastname

  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
        // Wykonanie żądania
        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 {

                    var nameDoctors = doctor.firstname
                    var lastnameDoctors = doctor.lastname
                    self.listDoctors.append(nameDoctors)
                }
            }
            }, failure: {
                (rkoperation: RKObjectRequestOperation!, error: NSError!) -> Void in
                print("Load filed with error: @", error!)
                self.performSelectorOnMainThread(#selector(AppDelegate.showFetchError), withObject: nil, waitUntilDone: true)
        })
        handler(listDoctors)
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.