我正在Swift中编写一个iOS应用程序,并且在结构和块方面存在一些问题.当用户编辑他的教育信息并单击保存按钮时,我向服务器发送请求并更新成功处理程序中的本地数据.在这里,我editItem()在类中编写了一个函数,EditController并editEducation()在类UserModel结构中编写了一个函数:
class EditController: UITableViewController {
//...
func editItem<T>(item: T, completion: () -> Void) {
switch selectedType {
case .Education:
let educationItem = item as! EducationModel
// self.user is a object of type "UserModel"
user!.editEducation(index: selectedRow, educationItem: educationItem) {
// breakpoint 2 here
completion()
self.tableView.reloadData()
}
default:
return
}
}
//...
}
struct UserModel {
//...
var education = [EducationModel]()
//EducationModel is also a structure
//...
mutating func editEducation(#index: Int, educationItem: EducationModel, completion: …Run Code Online (Sandbox Code Playgroud)