"locationManager"가있는 행에서 Xcode의 GPS를 설정할 때 위의 오류가 발생합니다. 무엇을해야할지 모르겠습니다. - 편집 - 나는 파일을 지 웠고 오류는 viewDidLoad 외부에 func locationManager 행을 추가하고 오류가 locationManager 행에 다시 나타날 때까지 수정되었습니다.선언 오류 앞에 로컬 변수 ""를 사용합니다.
코드 : 향후 참조를 위해
class ViewController: UIViewController, CLLocationManagerDelegate {
// labels
@IBOutlet var cityLabel: UILabel!
@IBOutlet var tempratureLabel: UILabel!
@IBOutlet var rainLabel: UILabel!
@IBOutlet var windLabel: UILabel!
@IBOutlet var humidityLabel: UILabel!
@IBOutlet var backgroundColor: UIImageView!
var locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
// USER GPS IN LAT/LON
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
// api
let client = APIClient(apiKey: "xxxxxxxxxxxxxxxxxxxxxxxx")
client.units = .Auto
client.getForecast(latitude: -75, longitude: -26) { (currentForcast, error) -> Void in
if let currentTemperature = currentForcast!.currently?.temperature {
self.tempratureLabel.text = String(currentTemperature)
let backgroundTemp = currentForcast!.currently?.temperature
//update background image per temp
if backgroundTemp <= 9 {
self.backgroundColor.image = UIImage(named: "Gradient1_Iphone6-GREY.png")
} else if backgroundTemp >= 10 && backgroundTemp <= 19 {
self.backgroundColor.image = UIImage(named: "Gradient1_Iphone6-DARKPURP.png")
} else if backgroundTemp >= 20 && backgroundTemp <= 29 {
self.backgroundColor.image = UIImage(named: "Gradient1_Iphone6-DARKBLUE.png")
} else if backgroundTemp >= 30 && backgroundTemp <= 39 {
self.backgroundColor.image = UIImage(named: "Gradient1_Iphone6-DGREEN.png")
} else if backgroundTemp >= 40 && backgroundTemp <= 49 {
self.backgroundColor.image = UIImage(named: "Gradient1_Iphone6-MIDPURP.png")
} else if backgroundTemp >= 50 && backgroundTemp <= 59 {
self.backgroundColor.image = UIImage(named: "Gradient1_Iphone6-MIDBLUE.png")
} else if backgroundTemp >= 60 && backgroundTemp <= 69 {
self.backgroundColor.image = UIImage(named: "Gradient1_Iphone6-LIGHTPURP.png")
} else if backgroundTemp >= 70 && backgroundTemp <= 75 {
self.backgroundColor.image = UIImage(named: "Gradient1_Iphone6-LIGHTBLUE.png")
} else if backgroundTemp >= 76 && backgroundTemp <= 78 {
self.backgroundColor.image = UIImage(named: "Gradient1_Iphone6-LGREEN.png")
} else if backgroundTemp >= 79 && backgroundTemp <= 81 {
self.backgroundColor.image = UIImage(named: "Gradient1_Iphone6_YELLOW.png")
} else if backgroundTemp >= 82 && backgroundTemp <= 87 {
self.backgroundColor.image = UIImage(named: "Gradient1_Iphone6_ORANGE.png")
} else if backgroundTemp >= 88 && backgroundTemp <= 98 {
self.backgroundColor.image = UIImage(named: "Gradient1_Iphone6-LIGHTRED.png")
} else {
self.backgroundColor.image = UIImage(named: "Gradient1_Iphone6-DARKRED.png")
}
}
//update minor labels
let rain = 10
self.rainLabel.text = String(rain) + " %"
let humidity = 10
self.humidityLabel.text = String(humidity) + " %"
let wind = 10
self.windLabel.text = String(wind) + " mph"
// Do any additional setup after loading the view, typically
}
func locationManager (manager: CLLocationManager! , didUpdateLocation locations: [AnyObject]!) {
print(locations)
}
func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
}
전체 소스 코드를 게시 할 수 있습니까? – fiks
아직 표시되지 않은 코드가 더 있습니까? 때때로 소스 파일의 오타가 컴파일러를 혼란스럽게 만들어 파일의 앞부분에 실수가 있다고 생각하게 만듭니다. 게시 한 내용에는 아무런 문제가 없습니다 (당연히 ** 제외). 파일에 다른 내용이 없으면 Xcode를 다시 실행하고 다시 작성하기 전에 제거하십시오. – Gruntcakes
Xcode를 다시 시작하거나 ('CMD + Shift + K') 청소 해 보셨습니까? – WMios