Ad

Our DNA is written in Swift
Jump

Should I switch to Swift?

Angelina asks:

I was very surprised when I heard about Swift.  I was curious what your thoughts are about Swift and phasing out Objective-C specifically since you are in the process of writing the Barcodes book.  Are you going to update your book to use Swift instead of Objective-C?

I mentioned previously that my book is feature complete. So the short answer is: No. The sample code is done and available to everybody who pre-ordered the early access version of the book.

So far I have identified a few things that are changing in iOS 8 which require minor modifications. Amongst them that Core Location now has two levels of location authorization, always or just when the app is in use. Apart from this I have not seen any advances in barcode technology (or related frameworks) in iOS 8 which would warrant new chapters or fundamental changes. If you want to build apps that leverage the built-in barcode scanner, you have to require iOS 7. And the chapters dealing with related technology also do. For example NSURLSession also requires it.

Then there is the timing about which iOS versions you should support if you are planning to release an app between now and the end of the year. When iOS 8 is released to the public, let’s assume October, you should continue to support iOS 7 for half a year, i.e. April 2015.  iOS is breaking adoption records with each new version, but you have to give your users some time to do it on their own pace. Since you have to support iOS 7 for barcode scanning, you might as well keep that as deployment target for this transition period.

On the other hand, if you are developing something to be released around the holiday season, you can start with iOS 8 as your baseline. The influx of many new devices being bought at that time favourably skews the number of your potential customers towards iOS 8. Here it depends if you want to use any of the new shiny APIs to more quickly build your app. But even if you do, the barcode scanning will work the same.

Lets make Angelina’s question a bit more broad:

“Does it make sense to migrate existing code to Swift?”

We have several closed and open sourced projects using Objective-C. There is nothing to be gained by rewriting everything in a new language. Apple lets you mix and match languages. If you add a new class to an existing project you may let yourself be tempted by the allure of Swift and use that for the implementation. Or even a new app is something that you can tackle in Swift right from the start to learn about it and be able to give feedback to Apple. I don’t see Swift replacing all of Objective-C development right away.

While Xcode 6 (and the contained LLVM compiler) are in BETA Apple reserves the right to make changes that might require tweaks in your source code. Another argument against rushing to Swift at this stage – especially for library vendors – is that there does not seem to be a way at present to keep methods private. Swift does not have headers, where you could only make visible the methods you want other developers to use. Which raises another question: how do you document libraries then? Right now I am using appledoc with specially formatted comments in my class headers.

If you must have HTML documentation which you can put on a web server you have to wait until appledoc supports Swift’s syntax. At this point you could have it scan the implementation files and it would find the /** */ comments, but it would fail to parse the method prototypes in Swift’s different syntax.

Conclusion

I’ll keep coding in Objective-C for the next few months and for existing projects. If I start a new open source project at a point when appledoc supports Swift, then I might look at doing the entire project in it. For existing apps I might try it for individual new classes, to get my bearings and get a feel for it. Or if there is a new app to be made, then I might try to do that entirely in Swift, too. But there is no reason to rush into a new relationship with a new language and abandon one you have grown to love over several years. Take your time to get to know each other first.

No question, Swift will eventually become the dominant language for developing on Apple platforms. But I foresee some remaining niches for where do do need to be able to drop down to C or assembly code. Any new technology that sees wide adoption always leaves some niches in existence where the replaced technologies dig in and remain in use. Just think of Vinyl LPs, CDs versus digital audio files.


Categories: Q&A

11 Comments »

  1. Just found a nicely discounted Swift course on Udemy…. 70% off till final release….

    https://www.udemy.com/swiftdeveloper/?couponCode=SWIFT-29

  2. Hello,

    Thanks for this nice article. I have worked on Android Apps and I am very new to iOS development. I have just started it. So in both Objective-C and Swift, I have no experience.
    So, should I start with traditional approach of Objective-C or Directly start with Swift?

Trackbacks

  1. Apple’s new Swift programing language looking better to iOS, Mac coders | Nagg
  2. Apple's new Swift programing language looking better to iOS, Mac coders | Hihid News
  3. Internet Info Apple’s new Swift programing language looking better to iOS, Mac coders | Internet Info
  4. » Swift : le langage de programmation d’Apple attire-t-il les développeurs ?Connaissances Informatiques
  5. Apple's new Swift programming language looking better to iOS, Mac coders | Hihid News