:我有问题。我创建列表医生显示名字和姓氏。如何反对名单医生
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)
最佳答案
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)
}
}
关于ios - 创建列表对象Swift,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37589459/