Building my first iOS app with Swift 2.0: Session IV

After three sessions, I am now getting to the fun part. I will be creating the data model first and then connecting it into the view so that I can add and show non-static data.

I will keep the Idea model simple. There is an Idea.title and an Idea.Detail. To access the object instances, I will need AddIdea(), DeleteIdea() and GetIdea() methods that are handled by something called a IdeaManager.

Idea class
IdeaManager class

Now, we can connect these models to the view. I’ll do this in three parts in this session:

Showing and hiding the keyboard

Novice-tip: In your simulator, I needed to uncheck ‘Connect Hardware Keyboard’ to have the keyboard on the simulated phone show up when testing.

I need to do a couple of things:

Methods that hide the keyboard when the UITextField and UITextView are selected and ‘Done’ buttons are pressed.
Aiight, I now can do showing and hiding (mainly hiding) the keyboard.

Now, let’s make the buttons have state.

For the ‘Done’ button, I want to disable it until there is text in the UITextView for the detailContent. And I want to disable the ‘Add’ button until there is text in the UITextFiled and the UITextView.

So, I did a couple of things:

My buttons have state!
The ‘Done’ & ‘Add’ buttons are disabled until the text fields they are associated with are ready.

Now let’s see if we can save these text fields.

Side-note: I had to re-write the Idea and IdeaManager classes again as I might have dropped the local stashed changes on my dev system. Not important, but having the code described above helped me rewrite that code very quickly.

To save the text fields I did a few things:

addButton_click that calls IdeaManager.AddIdea()
Updated tableView in ViewController to get the idea element from the ideas array in IdeaManager
My mom will be proud. Starting with an empty list, I can add an idea with a title and a detail field.

Boom! that was a productive session. I can now show and add non-static data. Code is on GitHub.



Co-founder & CTO at @ilovemaxwell. Previously founded @brightfunds.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store