我目前正在致力于为 IOS 创建一个框架。我的框架必须向服务器发送请求,解析响应,然后更新应用程序主页的 UITableView。 我已经创建了一个单例类“MyUpdater”,它有一个静态函数“addRow” 在我的应用程序中,我有 2 个对象:tableView 和我用于 tableView 的对象列表。 我希望(我的 FrameWork 的)“addRow”方法将对象异步添加到应用程序的对象列表中。 所以我创建了以下方法:
public static func addRow(tableView: UITableView, list: inout Array<Product>){
var my_object = Object()
list.insert(my_object, at: 1)
tableView.beginUpdates()
tableView.insertRows(at: [IndexPath(row: 1, section: 0)], with: .automatic)
tableView.reloadData()
tableView.enUpdates()}
我收到以下错误:转义闭包只能捕获 inout。
如何从 pod(框架)异步更新应用程序列表? 谢谢。 亲切的问候
最佳答案
为什么使用inout
?我认为这在这里没有意义,因为 inout 不是引用传递。
您是否尝试过类似的操作:?
public func addRow(tableView: UITableView, list: Array<Product>){
Dispatch.main.async {
//update the list + tableview
}
}
关于Swift (IOS) 更新异步函数中的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44888280/