Skip to content

Making MemeMe: Sometimes the Simplest Answer is the Right Answer

Welcome to “Making MemeMe” where I chronicle my adventures and discoveries in creating the second portfolio app in Udacity’s iOS Developer Nanodegree.

I’m amazingly talented at overcomplicating problems. My college mentor liked to point this out to me whenever I was struggling with the code I’d written.

You should also watch me solve a KenKen puzzle.

My recent case of overcomplicating matters had to do with clearing text in text fields. For some reason, I thought there had to be some property that cleared text existing somewhere in the Apple ecosystem. I assumed it would be akin to clearsOnBeginEditing. Maybe it would just be clears. I searched high and low in Apple documentation and on the Google, but no one seemed to have the answer I sought.

Turns out it was because the answer I sought didn’t exist. The actual answer was ridiculously simple and staring me right in the face.

func textFieldDidBeginEditing(textField: UITextField) {
  if textField.text == "TOP" || textField.text == "BOTTOM" {
  textField.text = ""
  }
}

Yep, that’s right! I only needed to set the text field to an empty string. No fancy properties necessary, just a simple assignment.

And that, ladies and gentlemen, is why you should always consider the simple answer. It’s usually the right one.

 

Published inios

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *