2016-07-21 1 views
2

"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. 
     } 
    } 
} 
+0

전체 소스 코드를 게시 할 수 있습니까? – fiks

+0

아직 표시되지 않은 코드가 더 있습니까? 때때로 소스 파일의 오타가 컴파일러를 혼란스럽게 만들어 파일의 앞부분에 실수가 있다고 생각하게 만듭니다. 게시 한 내용에는 아무런 문제가 없습니다 (당연히 ** 제외). 파일에 다른 내용이 없으면 Xcode를 다시 실행하고 다시 작성하기 전에 제거하십시오. – Gruntcakes

+0

Xcode를 다시 시작하거나 ('CMD + Shift + K') 청소 해 보셨습니까? – WMios

답변

2

:

당신이 선언 오류 전에 ""지역 변수의

사용과 같은 이상한 오류가 발생하는

당신은 그것을 분명히 인식하지 못한다는 것을 알아야합니다. (""는 변수 이름이 아니므로) 입력했습니다.

해결책은 대개 '켜고 끄기 (Xcode 다시 시작)'또는 'CMD + Shift + K'을 삭제하고 CMD + B을 빌드하는 것입니다.

또한, viewDidLoad의 내부

func locationManager (manager: CLLocationManager! , didUpdateLocation locations: [AnyObject]!) { 

을 추가했다. 외부로 이동해야합니다.

3

이것이 도움이 될지 모르지만 함수의 여는 중괄호와 닫는 중괄호를 엉망으로 만들었습니다. 직접 디버깅하기 전에 인터넷 검색을 시도했습니다. 바보 나! 그것은 사물 (이 self.legs을 참조하는 경우 완벽하게 괜찮습니다) 상단까지 다리가 아래의 지역 범위의 legs 사용하도록 구성 되었기 때문에

+0

이것은 제 문제였습니다. 'print' 문에서이 에러를 보았고 나중에 코드에서 표현 뒤에 잘못된 쉼표가있었습니다. 그것을 제거하면 그것을 고쳤습니다. –

0
class cat { 
    var legs? = 4 
    func manuallyCountLegs() -> Int { 
    guard legs ?? 0 < 50 else { 
     // Bail, I don't have time for this much counting 
     return legs ?? 0 
    } 
    let legs = self.legs 
    ... 
    } 
} 

이 실패합니다.

관련 문제