Skip to content

Argument passed to call that takes no arguments #393

@318bhojabr

Description

@318bhojabr

I'm getting this error in the AppDelegate, but I'm not sure what the problem might be. Any help is appreciated, thanks!

(the exact line that has the error is: "let detailsViewModel = DetailsJobView(details: details)" in the "private func loadDetails" section)

Btw, the error underlines the "d" in the second "details" in (details: details)

I've noted it in the code, but it might be hard to find.

import UIKit
import Firebase
import CoreLocation
import Moya

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

let window = UIWindow()
let locationService = LocationService()
let homeStoryboard = UIStoryboard(name: "Home", bundle: nil)
let service = MoyaProvider<YelpService.BusinessesProvider>()
let jsonDecoder = JSONDecoder()
var navigationController: UINavigationController?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    
    // Change color of tab bar items
    UITabBar.appearance().tintColor = .black
    FirebaseApp.configure()

    jsonDecoder.keyDecodingStrategy = .convertFromSnakeCase

    locationService.didChangeStatus = { [weak self] success in
        if success {
            self?.locationService.getLocation()
        }
    }

    locationService.newLocation = { [weak self] result in
        switch result {
        case .success(let location):
            self?.loadJobs(with: location.coordinate)
        case .failure(let error):
            assertionFailure("Error getting the users location \(error)")
        }
    }

    switch locationService.status {
    case .notDetermined, .denied, .restricted:
        let locationViewController = homeStoryboard.instantiateViewController(withIdentifier: "LocationViewController") as? LocationViewController
        locationViewController?.delegate = self
        window.rootViewController = locationViewController
    default:
        let nav = homeStoryboard
            .instantiateViewController(withIdentifier: "JobNavigationController") as? UINavigationController
        self.navigationController = nav
        window.rootViewController = nav
        locationService.getLocation()
        (nav?.topViewController as? JobTableViewController)?.delegete = self
    }
    window.makeKeyAndVisible()
    
    return true
}

private func loadDetails(for viewController: UIViewController, withId id: String) {
    service.request(.details(id: id)) { [weak self] (result) in
        switch result {
        case .success(let response):
            guard let strongSelf = self else { return }
            if let details = try? strongSelf.jsonDecoder.decode(Details.self, from: response.data) {
                let detailsViewModel = DetailsJobView(details: details)    ### **_//ERROR IS HERE_**

                (viewController as? DetailsJobViewController)?.viewModel = detailsViewModel
            }
        case .failure(let error):
            print("Failed to get details \(error)")
        }
    }
}

private func loadJobs(with coordinate: CLLocationCoordinate2D) {
    service.request(.search(lat: coordinate.latitude, long: coordinate.longitude)) { [weak self] (result) in
        guard let strongSelf = self else { return }
        switch result {
        case .success(let response):
            let root = try? strongSelf.jsonDecoder.decode(Root.self, from: response.data)
            let viewModels = root?.jobs
                .compactMap(JobListViewModel.init)
                .sorted(by: { $0.distance < $1.distance })
            if let nav = strongSelf.window.rootViewController as? UINavigationController,
                let jobListViewController = nav.topViewController as? JobTableViewController {
                jobListViewController.viewModels = viewModels ?? []
            } else if let nav = strongSelf.homeStoryboard
                .instantiateViewController(withIdentifier: "JobNavigationController") as? UINavigationController {
                strongSelf.navigationController = nav
                strongSelf.window.rootViewController?.present(nav, animated: true) {
                    (nav.topViewController as? JobTableViewController)?.delegete = self
                    (nav.topViewController as? JobTableViewController)?.viewModels = viewModels ?? []
                }
            }
        case .failure(let error):
            print("Error: \(error)")
        }
    }
}
}

extension AppDelegate: LocationActions, ListActions {
func didTapAllow() {
    locationService.requestLocationAuthorization()
}

func didTapCell(_ viewController: UIViewController, viewModel: JobListViewModel) {
    loadDetails(for: viewController, withId: viewModel.id)
}
}

Here is the DetailsJobView:

import UIKit
import MapKit

@IBDesignable class DetailsJobView: CoreView {
@IBOutlet weak var collectionView: UICollectionView?
@IBOutlet weak var pageControl: UIPageControl?
@IBOutlet weak var priceLabel: UILabel?
@IBOutlet weak var hoursLabel: UILabel?
@IBOutlet weak var locationLabel: UILabel?
@IBOutlet weak var ratingsLabel: UILabel?
@IBOutlet weak var mapView: MKMapView?

@IBAction func handleControl(_ sender: UIPageControl) {

}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions