获取错误消息:“调用中传递了额外的尾随闭包”Swift

问题描述 投票:0回答:0

更新:函数

retrieveSelectedRestaurantDetailViewInfo
的代码发布在帖子中间的下方。

我在下面的代码块中收到错误消息:“

Extra trailing closure passed in call
”:

retrieveSelectedRestaurantDetailViewInfo(selected_restaurant_business_ID: theMapVenue.id!) { (response, error) in

                if let response = response {
                    //Got error in below line of code. May not need to use below line of code. Try and figure out correct code for below line of code, if adding code inthere similar to commented out below line of code makes program/project better.
                    self.selectedVenueDetailViewInfo = response
                    DispatchQueue.main.async {
                        self.scrollableCitiesRestaurantDetailsTableView.reloadData()
                    }
                }
}

我在代码行中收到错误消息(在上面的代码块中):

retrieveSelectedRestaurantDetailViewInfo(selected_restaurant_business_ID: theMapVenue.id!) { (response, error) in

retrieveSelectedRestaurantDetailViewInfo
函数的代码如下。

RetrieveSelectedRestaurantDetailViewInfo.swift

import Foundation
import UIKit
import CoreLocation

extension UIViewController {
    
    func retrieveSelectedRestaurantDetailViewInfo(
        selected_restaurant_business_ID: String)
    
    async throws -> SelectedRestaurantDetailViewInfoNotUsingCodable? {
        
        // MARK: Make API Call
        let apiKey = ApiKey
        
        let baseURL =
        "https://api.yelp.com/v3/businesses/\(selected_restaurant_business_ID)"

        let url = URL(string: baseURL)

        /// Creating Request
        var request = URLRequest(url: url!)
        request.setValue("Bearer \(apiKey)", forHTTPHeaderField: "Authorization")
        request.httpMethod = "GET"
        
        let (data, response) = try await URLSession.shared.data(for: request)
        
        let json = try JSONSerialization.jsonObject(with: data, options: [])
        
        let responseDictionary = json as? NSDictionary
        
        var selectedVenue = SelectedRestaurantDetailViewInfoNotUsingCodable(hours: OpenHoursForDaysOfWeek(mondayOpenHoursWithoutDay: "Starting Text",
                                   tuesdayOpenHoursWithoutDay: "Starting Text",
                                   wednesdayOpenHoursWithoutDay: "Starting Text",
                                   thursdayOpenHoursWithoutDay: "Starting Text",
                                   fridayOpenHoursWithoutDay: "Starting Text",
                                   saturdayOpenHoursWithoutDay: "Starting Text",
                                   sundayOpenHoursWithoutDay: "Starting Text",
                                   numberOfOpenHoursTimeRangesAsStringTypeOfTableViewCellToUse: "Starting Text"))
        
        //Accessing Business Data
        selectedVenue.name = responseDictionary?.value(forKey: "name") as? String
        
        //*Code to account for if selectedVenue.name is nil, or if it doesn't have any text, specfically has/is "", or if it only has a space specfically like this: " ".*
        
        //*Code for accessing the rest of the detail info for the user-selected restaurant (address, business hours, etc.), is similar to the above code for accessing the business name above, and also accounts if the other info accessed is nil, or if it doesn't have any text, specfically has/is "", or if it only has a space specfically like this: " ".*
        
        //Code for accessing business hours info. Included it here since its a little different than accessing the rest of the business information above.
        if let hoursDictionariesForHoursManipulation = responseDictionary?.value(forKey: "hours") as? [NSDictionary] {
            
            selectedVenue.hours = self.manipulateSelectedRestaurantHoursInfoAndRecieveFormattedHoursInfoToUse(selected_restaurant_business_hours: hoursDictionariesForHoursManipulation)
        }
        
        return selectedVenue
    }
}

我试过的一件事:查看代码块中使用了谁的模型的模型属性是否适当地设置为 var/set。想法来自此页面:https://www.hackingwithswift.com/forums/100-days-of-swiftui/day-88-extra-trailing-closure-passed-in-call/10731.

我认为可能导致此错误消息的原因:

-没有为

error
创建变量,因为对于我在 Stack Overflow 上找到的相同类型的错误消息有类似的解决方案:Error=Extra trailing closure passed in call,.

-此错误消息可能是由导致上述同一代码块中的另一个错误消息的原因引起的,此错误消息为:“

Cannot assign value of type '_' to type ‘SelectedRestaurantDetailViewInfoNotUsingCodable’
”,在代码行中:

self.selectedVenueDetailViewInfo = response

SelectedRestaurantDetailViewInfoNotUsingCodable
被分配给
selectedVenueDetailViewInfo
在上面发布的代码片段的同一代码文件中更“上面”,这里没有显示。

我还没有找到第二个错误消息的任何潜在解决方案。

如何至少解决本文中提到的第一条错误消息?

ios swift closures function-call dispatch-queue
© www.soinside.com 2019 - 2024. All rights reserved.