11 Feb 2015
As per my previous posts, I’m developing an iOS app “in the open” using Swift as a learning experiment. It’s going to be an app that counts down the days to a future date.
Data Model design
I thought a good way of getting started would be to work on the data model code. There would be more pure Swift code to write to get up to speed on the syntax, plus I’d get the chance to write some unit tests too.
The data model design is pretty straightforward; I want to have the following properties to hold the settings data:
- start: NSDate
- end: NSDate
- title: String
- weekdaysOnly: Bool
Then there are three different access properties/methods to calculate various day lengths:
- DaysLength: Int - the number of inclusive days between the start and the end
- DaysGone(currentDate: NSDate) -> Int - the number of days from the start to the current date
- DaysLeft(currentDate: NSDate) -> Int - the number of days to the end to the current date
Writing a simple class to implement this logic was pretty simple even in a new language, although a few things were a little strange at first in Swift.
Semi-colons at the end of the line are optional in Swift, and a few references I found seemed to say best practice is not to add them, although muscle memory from Objective-C and C# made this hard to do.
Also integrating into the IOS Foundation classes was a little strange in places especially the use of optional values. For example, note the ! at the end of this line
model.start = NSCalendar.autoupdatingCurrentCalendar().dateFromComponents(startComponents)!
model.start is of type
NSDate i.e. can’t be null, whereas
dateFromComponents() can return a null value,
! forces this to actually return a value (I think!). Not the most intuitive, but thankfully the Xcode editor prompted me to add the exclamation point.
The other problem I had initially was being able to reference the DaysLeftModel class from my unit test code. I couldn’t figure out anyway of importing the model code, before this very helpful blog post by Andrew Bancroft pointed out the way of configuring the build settings to automatically create a module.
For the date logic of calculating the difference between two dates ignoring weekends was a little tricky, but as usual the Internet was my friend and with the help of TDD and the algorithm outlined in this article by Alec Pojidaev I managed to get it working correctly.
So I’m happy to be up and running in Swift, and the code is up at GitHub if you’re interested.
I think I’ll next tackle storing these settings in a local datastore, as well as synching them with the cloud to share across devices.
Previous posts in the series
The code for the project is also available on GitHub
04 Feb 2015
I’m currently in-between contracts, so as promised last week I’m going to try developing a new app in Swift "in the open" and see how we get on.
My idea is to write a simple app that basically counts down how many days left until a certain date. This was inspired by the fact that in my last contract I used a spreadsheet to count down how much I had left to go (it wasn’t that bad really!)
I wanted something simple enough that could be completed in a few days - even though I know very little Swift before starting - and could be extended into an Apple Watch app.
Now there are hundreds of similar apps out there in the app store already, so this isn’t going to be groundbreaking in any way, but hopefully when it’s done it’ll find a small audience.
Before starting coding, obviously I want to do a little planning.
I’m very much a believer in doing just enough planning to get started along the right path, and if I had a test team enough information for them to understand what the app should do (but no more).
I’ve finally broken into my Evernote Moleskin notebook to sketch out a mini-design for the main app, and used the Evernote Scannable app to snap a picture:
Beautiful or what?
More usefully, I’m tracking the actual tasks in a Trello board which you should be able to see if you’re interested.
The initial tasks on the backlog - in probable order of development - are:
- Code to handle settings in iCloud
- Settings view to handle input etc.
- Simple main page to show days left
- Unit tests for calculations
- Daily notifications
- Today screen widget
- Watch extension
- Main page animations
18 Jan 2015
It’s clearly been a while since I updated my blog here, so I thought I’d give a quick update, and then share
my plan for getting me to share a bit more regularly what I’m up to.
Since my last post (6 months ago!) I’ve shipped my second iOS app - and Instagram client focusing on location called
Pixagogo. I learnt a hell of a lot making it,
and we have regular users from all around the world enjoying a different way of enjoying Instagram pictures.
We’ve also shipped several updates to our Daily Optimiser app, and now it’s
a paid app we have a small band of regular and hopefully happy users.
Unfortunately my fledgling business isn’t bringing in enough money to pay the bills yet, so for the last few
months I’ve been contracting at Sage in Newcastle working on a confidential project
doing financial website stuff (which is as much as I can and want to say).
While we ponder our next major app, I want to keep learning by building things. So my plan is
to build an app in the open where I can do the following things:
- Build something in Swift
- Something simple that I can ship in a few hours work
- Use the WatchKit SDK for something that might work on the Apple Watch when it ships
- Share the code on Github
- Blog about what I’m learning along the way
I have an idea what I’m going to do, and hopefully will start working on this during the next week.
If that’s true, there should be a new post here a bit sooner than the last interval :(
03 Jul 2014
So I’ve left Microsoft/Bing once again (lost count how many times I’ve come and gone).
My contract had expired at the end of June, and I think it’s time to do something away from search for a while.
I’m currently looking for contract work where I can be more flexible in my location - which I guess
means working at home for most of the time.
Over the last few months I’ve been working hard on the all-new iPad version of Daily Optimiser app.
I’ve learnt a hell of a lot about iOS development in the process, and am really proud of what we’ve built.
Checkout the website for full details of what the app does.
It should be in the App Store within days (assuming it passes the review process), but if you want to be a beta tester
for this or future versions, drop me an email and I’ll set you up.
Now I have a bit more time I’m hoping to blog a lot more about what I’m learning along the way. We will see as I’ve said that before :)
24 May 2014
I’ve been thinking for a while I have too many blogs I’ve created over time, so I decided to try and
consolidate them in just a couple of places.
This blog seemed the most sensible place to hold my “technical” blog posts, and the real challenge
was to pull in some pretty old posts going back to 2005(!) from my old MSDN Blog.
The Jekyll RSS importer did a reasonable job of getting the “newest” 15 posts,
but they weren’t the fill articles, so a major copy and paste job entailed to get everything working.
A couple of things I noticed when going through these old posts are:
- Old HTML editors based on IE Trident are terrible - some of the saved HTML was truly horrendous
- I’ve hated the Visual Studio unit test runner for ages, and it’s still not any better
One of the earliest posts about XML namespaces
is still getting comments on MSDN every so often, and is surprisingly the most useful thing I’ve ever written.
Anyway, it makes me happy that all these posts are now in one place and in HTML and Markdown files, so I can easily port them whenever I want in the future.