Test Driven Development in iOS with Swift

At Intuit we work in 2 week sprints. Last sprint I decided to take a story about a crash happening in an image downloader class. After looking at it for a bit, I decided it would be a great candidate to rewrite using dispatch groups, and also in Swift. (It’s an internal goal to rewrite when we can in Swift).

At first it was rough going and slow. The write a test, run it, and fail felt far slower than just writing the class from scratch, and then debugging it inside the app.

But – I really wanted to give it a try, so I changed my layout in Xcode. Instead of having the source in my left source panel in Xcode, I decided to put the unit test file there. And then on the right side I split that into two panels: the new Swift downloader source, and the old Objective C source.

That changed my focus from writing the source, to writing the tests, and then making the tests pass. I know it sounds like a small thing, but for me it really worked.

I also decided to embrace the “slowness” of TDD. It gave me more time to think about what I was writing and how to make sure it covered all the cases.

In short, something I feel I could have finished in a few days (with no tests) took me 5 days (along with meetings, production support, etc). But I got into it and really enjoyed it. I’d recommend you give it a try!

Swift With Objective C Tip 1

If you’ve started down the road of incorporating Swift into an Objective C project, and run into an error when adding calling a method in your Swift class that Xcode says isn’t there, or doesn’t autocomplete, try the following:

  • Add your #import “module-Swift.h” to your Objective C .m file. (In my case it’s #import “AppName-Swift.h”.
  • If that doesn’t work, recompile. You’ve probably just added a method in your Swift file, and Xcode needs a chance to compile it and add it to that auto-generated module-Swift.h file

Hopefully I’ll have more tips as I use Swift more and more at work. Stay tuned.

Learning Swift, Part 1

I’ve been attempting to, in my spare time, do more Swift development. The hardest thing for me so far is struggling knowing that I could do something in two minutes than in Swift takes me 20-30 minutes to search for and explore an answer and get the code in the correct format. 

It would be easy to slip back to Objective C to just “get it done”. But I think Swift is important now to spend the time to start using and learning. 

Minimum vacation policy

Instating an open vacation policy can be poison for your people’s team and happiness, as it removes the lower barrier of what’s an acceptable amount of time to be away and focus on recharging and your family, in short, your personal well-being. Your job as a company isn’t to coerce your people into taking as little time off as possible, it’s to make sure they have a good balance between work and life.

http://www.paperplanes.de/2014/12/10/from-open-to-minimum-vacation-policy.html

WWDC 2014 Recap

This years WWDC was pretty amazing in my mind – I didn’t get a ticket, but as I sat and watched the keynote, I keep being surprised. Granted I was off on my prediction (September 9th anyone?), but Apple had so much new and exciting stuff for developers that week that I’m still taking it in and watching videos.

Brent Simmons again has a great post on his initial reactions, and mine were very similar.

My biggest surprise and excitement for the future of Apple was Swift. What a great way to induce excitement back into a developer platform than to change the fundamental language we develop in.

Yes, I love Objective C, but I’ve been doing it a long time. I’m by no means an expert, but I’m pretty good. I’m excited to learn Swift, to write some apps in Swift, and to move with Apple to the future of developing apps for their products.

I’m also excited for the future of Apple hardware and Swift. With Apple owning the language, the compiler for the language, and the chip that the language runs on, I wonder what performance increases they can get out of it.

Also, think about the future of AppKit and UIKit. With Swift, what changes in those frameworks? What new functionality will be only available in Swift?

In conclusion, this WWDC has re-invigorated me as an Apple developer, and gotten me very excited for the future of Apple.

Bring on September 9th. 

Brent On Taking A Break

Brent Simmons comments on Marco’s fight on the internet, and Twitter’s affect on people. Best quote:

Twitter is also wonderful, and I get so much value out of it. But it’s like 51% good and 49% bad.