Я пытаюсь вручную создать некоторый текст-заполнитель для UITextView, и когда я пытаюсь установить текст заполнителя, я получаю ошибку компилятора Swift. Xcode сообщает мне, что он ожидал объявления для pinContent, где я сначала пытаюсь установить его текстовое значение. Вот мой код:Ошибка Swift компилятора при ссылке на существующую переменную
class FirstViewController: UIViewController {
@IBOutlet var pinTitle: UITextField!
@IBOutlet var pinContent: UITextView!
@IBAction func createPin(sender: AnyObject) {
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
println(userLocation)
}
// Manually create a placeholder for the text view
pinContent.text = "Description" // This line is where I get my error
pinContent.textColor = UIColor.lightGrayColor()
// Change the text properties of the text view when the user begins editing, so it types in the normal black font
func textViewDidBeginEditing(textView: UITextView) {
if textView.textColor == UIColor.lightGrayColor() {
textView.text = nil
textView.textColor = UIColor.blackColor()
}
}
// If the user leaves the text view blank when they're done editing, re-set the placeholder
func textViewDidEndEditing(textView: UITextView) {
if textView.text.isEmpty {
textView.text = "Description" // Sometimes I get the same error here as well
textView.textColor = UIColor.lightGrayColor()
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Move, что код в метод (например, в viewDidLoad) ... –