Ios “如何修复”;调用中缺少参数标签;斯威夫特3

Ios “如何修复”;调用中缺少参数标签;斯威夫特3,ios,swift,swift3,ios10,Ios,Swift,Swift3,Ios10,我完全是swift和ios编程的初学者 我在看了一段由swift 1和xcode 6 beta编写的编码课程视频后遇到了一个问题。 我知道swift的版本已经改变了,语法也改变了很多。 我已经解决了一些问题,但仍然有一个我无法解决。 这是“调用中缺少参数标签” 以下是我的代码: import UIKit import CoreLocation class ViewController: UIViewController,CLLocationManagerDelegate { let loca

我完全是swift和ios编程的初学者 我在看了一段由swift 1和xcode 6 beta编写的编码课程视频后遇到了一个问题。 我知道swift的版本已经改变了,语法也改变了很多。 我已经解决了一些问题,但仍然有一个我无法解决。 这是“调用中缺少参数标签”

以下是我的代码:

import UIKit
import CoreLocation

class ViewController: UIViewController,CLLocationManagerDelegate {

let locationManger:CLLocationManager = CLLocationManager()

@IBOutlet weak var location: UILabel!
@IBOutlet weak var icon: UIImageView!
@IBOutlet weak var temperature: UILabel!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    locationManger.delegate = self

    locationManger.desiredAccuracy = kCLLocationAccuracyBest

    if(ios10()) {
        locationManger.requestWhenInUseAuthorization()
    }
    locationManger.startUpdatingLocation()
}

func ios10() ->Bool {
    return UIDevice.current.systemVersion == "10.2"
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]){
    let location:CLLocation = locations[locations.count-1] as CLLocation

    if(location.horizontalAccuracy > 0) {
        print(location.coordinate.latitude)
        print(location.coordinate.longitude)
        self.updateWeatherInfo(latitude: location.coordinate.latitude,longitude: location.coordinate.longitude)
        locationManger.stopUpdatingLocation()
    }
}

func updateWeatherInfo(latitude:CLLocationDegrees,longitude:CLLocationDegrees){
    let manager = AFHTTPRequestOperationManager()
    let url = "http://api.openweathermap.org/data/2.5/weather?APPID=c5a8f49ee6e86f1aaa2be178f25f37f2"
    let params = ["lat":latitude,"lon":longitude,"cnt":0]

    manager.get(url,
                parameters: params,
                success: { (operation:AFHTTPRequestOperation!, responseObject: Any!) in
                    print("JSON:" + (responseObject as AnyObject).description!)

                    updateUISuccess(responseObject as! NSDictionary!)  
//that's where my error1 :missing argument label 'jsonResult' in call
                }
    )
}

func updateUISuccess(jsonResult:NSDictionary){

    if let tempResult = (jsonResult["main"] as? [String:Double])?["type"] {
        //if let tempResult = (jsonResult["main"] as? [String:Double])?["type"]  current
        //if let tempResult = jsonResult["main"]?["temp"]? as? Double   pre

        var temperature:Double
        if ((jsonResult["sys"] as? [String:String])?["country"] == "US"){
            //CONVERT TO FAHRENHEIT IF USER IN US
            temperature = round(((temperature - 273.15) * 1.8) + 32)
        }
        else{
            //CONVERT TO CELSIUS
            temperature = round(temperature - 273.15)
        }

        self.temperature.text = "\(temperature)°"
        print(temperature)

        var name = jsonResult["name"] as! String
        self.location.text = "\(name)"


        var conditionArray = (jsonResult["weather"] as! NSArray)[0] as! NSDictionary  
        var condition = conditionArray["id"] as! Int    

        var sunrise = (jsonResult["sys"] as? [String:Double])?["sunrise"]
        var sunset = (jsonResult["sys"] as? [String:Double])?["sunset"]

        var nightTime = false
        var now = NSDate().timeIntervalSince1970

        if (now < sunrise! || now > sunset!) {
            nightTime = true
        }
        //self.icon.image = UIImage(named:"sunny")
        updateWeatherIcon(condition,nightTime: nightTime)
//that's where my error2 :missing argument label 'condition:' in call
    }
    else {
        print("error!")
    }


}

func updateWeatherIcon(condition: Int,nightTime: Bool){
    //thunderstorm
    if(condition < 300) {
        if nightTime {
            self.icon.image = UIImage(named:"tstorm1_night")
        }
        else {
            self.icon.image = UIImage(named:"tstorm1")
        }
    }
        //drizzle
    else if (condition < 500) {

    }
        //rain
    else if (condition < 600) {

    }
        //snow
    else if (condition < 700) {

    }
        //fog
    else if (condition < 771) {
        if nightTime {
            self.icon.image = UIImage(named: "fog_night")
        }
        else {
            self.icon.image = UIImage(named: "fog")
        }
    }
        //tornado
    else if (condition < 800) {
        self.icon.image = UIImage(named:"tstorm3")
    }
        //clear
    else if (condition == 800) {
        if nightTime {
            self.icon.image = UIImage(named:"sunny_night")
        }
        else {
            self.icon.image = UIImage(named:"sunny")
        }
    }
        //few clouds
    else if (condition < 804) {
        if nightTime {
            self.icon.image = UIImage(named:"cloudy2_night")
        }
        else {
            self.icon.image = UIImage(named:"cloudy2")
        }
    }
        //overcast
    else if (condition == 804) {
        self.icon.image = UIImage(named:"overcast")
    }
        //extreme
    else if ((condition >= 900 && condition < 903) || (condition >= 904 && condition < 1000)){
        self.icon.image = UIImage(named:"tstorm3")
    }
        //cold
    else if (condition == 903) {
        self.icon.image = UIImage(named:"snow5")
    }
        //hot
    else if (condition == 904) {
        self.icon.image = UIImage(named:"sunny")
    }
        //dont know
    else {
        self.icon.image = UIImage(named:"dono")
    }
}



func locationManager(_ manager: CLLocationManager, didFailWithError error: Error){
    print(error)
}

}
导入UIKit
导入核心定位
类ViewController:UIViewController、CLLocationManagerDelegate{
让LocationManager:CLLocationManager=CLLocationManager()
@IBVAR位置:UILabel!
@IBVAR图标:UIImageView!
@IBVAR出口弱var温度:UILabel!
重写func viewDidLoad(){
super.viewDidLoad()
//加载视图后,通常从nib执行任何其他设置。
locationManger.delegate=self
locationManger.desiredAccuracy=KCallocationAccuracyBest
if(ios10()){
LocationManager.RequestWhenUseAuthorization()
}
LocationManager.startUpdatingLocation()
}
func ios10()->Bool{
返回UIDevice.current.systemVersion==“10.2”
}
重写函数didReceiveMemoryWarning(){
超级。我收到了记忆警告()
//处置所有可以重新创建的资源。
}
func locationManager(manager:CLLocationManager,didUpdateLocations位置:[CLLocation]){
让location:CLLocation=locations[locations.count-1]作为CLLocation
如果(位置水平精度>0){
打印(位置、坐标、纬度)
打印(位置、坐标、经度)
updateWatherInfo(纬度:位置。坐标。纬度,经度:位置。坐标。经度)
LocationManager.StopUpdatengLocation()文件
}
}
func updateWeatherInfo(纬度:CLLocationDegrees,经度:CLLocationDegrees){
let manager=AFHTTPRequestOperationManager()
让url=”http://api.openweathermap.org/data/2.5/weather?APPID=c5a8f49ee6e86f1aaa2be178f25f37f2"
设params=[“lat”:纬度,“lon”:经度,“cnt”:0]
manager.get(url,
参数:params,
成功:{(操作:AFHTTPRequestOperation!,响应对象:Any!)在中
打印(“JSON:”+(responseObject作为AnyObject)。说明!)
updateUISuccess(响应对象为!NSDictionary!)
//这就是我的错误1:调用中缺少参数标签“jsonResult”
}
)
}
func updateUISuccess(jsonResult:NSDictionary){
如果让tempResult=(jsonResult[“main”]作为?[String:Double])?[“type”]{
//如果让tempResult=(jsonResult[“main”]作为?[String:Double])?[“type”]当前
//如果让tempResult=jsonResult[“main”]?[“temp”]?作为双前置
var温度:双
如果((jsonResult[“sys”]作为?[String:String])?[“country”]=“US”){
//如果用户在美国,则转换为华氏温度
温度=圆形((温度-273.15)*1.8)+32)
}
否则{
//换算成摄氏度
温度=圆形(温度-273.15)
}
self.temperature.text=“\(温度)°”
打印(温度)
var name=jsonResult[“name”]作为!字符串
self.location.text=“\(名称)”
var conditionArray=(jsonResult[“weather”]as!NSArray)[0]as!NSDictionary
var condition=conditionArray[“id”]as!Int
var sunrise=(jsonResult[“sys”]作为?[String:Double])?[“sunrise”]
var sunset=(jsonResult[“sys”]作为?[String:Double])?[“sunset”]
var nightTime=false
var now=NSDate().timeIntervalSince1970
如果(现在<日出!|现在>日落!){
夜间=真
}
//self.icon.image=UIImage(名为“sunny”)
UpdateWathericon(条件,夜间:夜间)
//这就是我的错误2:调用中缺少参数标签“条件:”
}
否则{
打印(“错误!”)
}
}
func updatewathericon(条件:Int,夜间:Bool){
//雷雨
如果(条件<300){
如果晚上{
self.icon.image=UIImage(名为:“tstorm1_night”)
}
否则{
self.icon.image=UIImage(名为:“tstorm1”)
}
}
//毛毛雨
否则如果(条件<500){
}
//雨
否则如果(条件<600){
}
//雪
否则如果(条件<700){
}
//雾
否则如果(条件<771){
如果晚上{
self.icon.image=UIImage(名为“雾之夜”)
}
否则{
self.icon.image=UIImage(名为“雾”)
}
}
//龙卷风
否则如果(条件<800){
self.icon.image=UIImage(名为:“tstorm3”)
}
//清楚的
否则如果(条件==800){
如果晚上{
self.icon.image=UIImage(名为:“阳光之夜”)
}
否则{
self.icon.image=UIImage(名为“sunny”)
}
}
//少云
否则如果(条件<804){
如果晚上{
self.icon.image=UIImage(名为:“cloudy2_night”)
}
否则{
self.icon.image=UIImage(名为:“cloudy2”)
}
}
//阴沉的
否则如果(条件==804){
self.icon.image=UIImage(名为:“阴天”)
}
//极端的
否则如果((条件>=900和条件<903)| |(条件>=904和条件<1000)){
self.icon.image=UIImage(名为:“tstorm3”)
}
//冷的
否则如果(条件==903){
self.icon.image=UIImage(名为“snow5”)
}
//热的
否则如果(条件==904){
self.icon.image=UIImage(名为“sunny”)
}
//不知道
否则{
self.icon.image=UIImage(名为“dono”)
}
}
func locationManager(manager:CLLocationManager,didFailWithError:error){
打印(错误)
}
}
我想知道如何修理它
多谢各位

错误是因为函数要求您命名要传入的参数。Tr
updateUISuccess(responseObject as! NSDictionary!)
updateUISuccess(jsonResult: responseObject as! NSDictionary!)
func updateUISuccess(_ jsonResult:NSDictionary){
updateWeatherIcon(condition,nightTime: nightTime)
updateWeatherIcon(condition: condition, nightTime: nightTime)