我想获得最终结果joblist数组以使用外部闭包。因为我想使用Joblist数组设置tableview。
let geoCoder = CLGeocoder()
geoCoder.geocodeAddressString(address) { (placemarks, error) in
if error == nil && (placemarks?.count)! > 0 {
let location2 = placemarks?[0].location
if let location1 = self.locationManager?.location {
let distanceInMeters = location1.distance(from: location2!)
let IntDis = Int(distanceInMeters)
//print(IntDis)
if IntDis < 40000 {
//print(address)
if let activityid = infoDictionary["ActivityID"] {self.newJob.ActivityID=activityid}
if let companyname = infoDictionary["CompanyName"] {self.newJob.CompanyName=companyname}
if let quantity = infoDictionary["Quantity"] {self.newJob.Quantity=quantity}
if let coupontitle = infoDictionary["Title"] {self.newJob.CouponTitle=coupontitle}
if let couponterms = infoDictionary["Terms"] {self.newJob.CouponTerms=couponterms}
if let expirdate = infoDictionary["ExpirDate"] {self.newJob.ExpirDate=expirdate}
if let contactperson = infoDictionary["ContactPerson"] {self.newJob.ContactPerson=contactperson}
if let tel = infoDictionary["TEL"] {self.newJob.TEL=tel}
self.joblist.append(self.newJob)
//print(self.joblist)
//self.tableView.reloadData()
}
}
}
}
答案 0 :(得分:0)
您可以通过两种方式执行此操作:
// prints out the array in uppercase
System.out.println(Arrays.toString(names10).toUpperCase());
变量设为全局,以便可以从多个位置访问全局变量:
joblist
使用回调(简单版本不会将自身传递给下一个函数):
let geoCoder = CLGeocoder()
var jobList = [AnyClass]() //make a global array
geoCoder.geocodeAddressString(address) { (placemarks, error) in
...filtering code ...
joblist.append(self.newJob)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
cell.textLabel = jobList[indexPath.row].ActivityID //or something else with the data
}