Argument passed to call that takes no arguments in Xcode

355 Views Asked by At

I have a UITableViewCell and when I'm running the code below,the codes that were running suddenly gave 3 error. I wrote the problem lines on the code but How can I solve this problem?

UITableViewCell: import UIKit import MapKit import Firebase import CoreLocation import SDWebImage

class anasayfaCell: UITableViewCell, MKMapViewDelegate, CLLocationManagerDelegate{

@IBOutlet weak var kullaniciAdiLabel: UILabel!
@IBOutlet weak var yorumLabel: UILabel!
@IBOutlet weak var kullaniciImagelabel: UIImageView!
@IBOutlet weak var yardimButonLabel: UILabel!
@IBOutlet weak var anasayfaHarita: MKMapView!
@IBOutlet weak var documentIdLabel: UILabel!

override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
    
    yardimButonLabel.text = "Yardım Bekliyor..."
    
    anasayfaHarita.layer.cornerRadius = 13
    anasayfaHarita.layer.masksToBounds = true
    layer.cornerRadius = 15
    layer.masksToBounds = true
    
    anasayfaHarita.isUserInteractionEnabled = false
    anasayfaHarita.isScrollEnabled = false
}

override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)
}

@IBAction func yardimEdildiSwitch(_ sender: UISwitch) {
    if (sender.isOn == true){
     let firestoreDB = Firestore.firestore()
        if let trueOrFalse = Bool(yardimButonLabel.text!) {
            let ValueStore = ["helped" : true ] as [String : Any]
            
            firestoreDB.collection("posts").document(documentIdLabel.text!).setData(ValueStore, merge: true)
        }
        
        
    }
    
}

func prepare(with post: Post) {
    kullaniciAdiLabel.text = post.ownerEmail
    yorumLabel.text = post.comment
    yardimButonLabel.text = String(post.helped)
    yardimButonLabel.text = String(post.id)
    
    
    
    if let imageURL = URL(string: post.imageURL) {
        kullaniciImagelabel.sd_setImage(with: imageURL)
    }
    
    let annotation = MKPointAnnotation()
    annotation.coordinate = CLLocationCoordinate2D(geoPoint: post.location).   **[Argument passed to call that takes no arguments]**
    annotation.title = "Yardım Noktası"
    annotation.subtitle = "Helpet"
    
    anasayfaHarita.addAnnotation(annotation)
    
    let span : MKCoordinateSpan = MKCoordinateSpan(latitudeDelta: 0.05,longitudeDelta: 0.05)
    let region = MKCoordinateRegion(center: CLLocationCoordinate2D(geoPoint: post.location), span: span)    **[Argument passed to call that takes no arguments]**
    
    anasayfaHarita.setRegion(region, animated: true)
}
1

There are 1 best solutions below

0
On

You are trying to create a CLLocationCoordinate2D using a non-existent initializer. Therefore, you can either create this custom initializer or convert the GeoPoint into a CLLocationCoordinate2D in some other way.

To fix your problem outright, just create the initializer:

import CoreLocation
import FirebaseFirestore

extension CLLocationCoordinate2D {
    init(geoPoint: GeoPoint) {
        self.init(latitude: geoPoint.latitude, longitude: geoPoint.longitude)
    }
}

Another way to go about this is to extend GeoPoint to give you a CLLocationCoordinate2D whenever you need it:

import CoreLocation
import FirebaseFirestore

extension GeoPoint {
    var coordinate2D: CLLocationCoordinate2D {
        return CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
    }
}

And to use it just access this property from a GeoPoint whenever you need a CLLocationCoordinate2D.

let annotation = MKPointAnnotation()
annotation.coordinate = post.location.coordinate2D