I'm Vitor navarro and this is my corner in the web, if you're here for any of my posts, projects or to know more about me, this is the right place.
[A programmer’s journey] Todo App with Swift - 01
Categories
Development
Tags
swift
tutorial
mobile
ios
Swift has been surfing the news waves quite some time by now even more after the Open Source Announcement. I have given the though of learning it day one, and to say the truth I read the Apple’s intro book when the first version came off, the problem was I didn’t wanted to commit to the language at that time.
I believe that the way to learning some kind of stuff, like programming languages, is through practicing. So this series of posts will present the birth of a simple Todo App from ground zero to the point it is exhausted, at least the point I think it is.
Did you get latest Xcode? Some Swift enable version please
Create a single view application, remember to enable tests
Now the project have:
A view controller
Main and LaunchScreen storyboards
The famous AppDelegate, if you’re an iOS developer
Pro tip: If you’re lost about the basics I strongly recommend to check the intro book mentioned before, is quite helpful
Why storyboard? This app isn’t complex enough that demands a nib or frame approach, and if that became true in the future then it can always be changed. Here is a post by Antonio Bello from Toptal dwelving further into the subject.
Todo Model
The todo item during this step is composed by two things:
content: the text that an user input as a to do
completed: the field that stores if that to do was completed
Also I added a bonus static method sample to create some pre-inserted data.
Todo list Cell - UITableViewCell
I created a simple UITableViewCell file just to store a checkbox image (UIImageView) and a title label, as long as switching the checkbox image properly. Also I want to improve the cell in the future.
Important to note that I built the cell UI directly into storyboard, to do that:
Table view content is at Dynamic Prototypes
Prototype Cells is set to 1
Changed the class to TodoTableViewCell
Set identifier to the same used in the TodosViewController
Todo list ViewController
Almost there, the only thing left is the ViewController. I didn’t mention how everything would work right?
Well the idea is similar to the todomvc online sample, at least the visual is and some features, not the code.
Initial features:
user can add a new todo in a simple input field
each new item is added to both all and todo lists
if the user check it as completed then the item is marked as completed, when unchecked we rollback the action
there are three states for the view: all, todo and completed lists. they are filter results from the all list
an user can remove a todo swiping left
What is used in the view
A toolbar (with all, todos and completed items)
Input field
Table view to show todos
Each section of code is commented and I made everything in the same class with the purpose of improving the code gradually.
Conclusion
Swift is quite beautiful to read and type
Is quite easier to create an iOS app if you already did it before in ObjC
It is not that hard if you don’t know ObjC
Reminds me of Ruby and Rust
Has some interesting features, watch this… this will have changed someday so pay a visit to swift.org