Background

In early 2014 Apple released a new language for creating iOS applications called Swift. In September 2014 Swift reached 1.0 status. Since then there have been many questions regarding Swift’s position relative to Objective-C, as well as the future of Objective-C.


Outlook

Our belief is that, at least in the near term, Swift will continue to co-exist with Objective-C. We expect both languages will also continue to get first class support for existing and new features as they are added to the iOS platform.


What is Swift?

Swift is a language that is based on C and Objective-C but is designed to make development and learning to develop iOS applications easier while introducing advanced language constructs such as generics and closures. Like Objective-C, Swift can access the full range of the Cocoa and Cocoa Touch APIs. In short, one may conclude that Swift is a better language for creating true native applications than Objective-C; however, this is not always the case. Like most other development languages, Swift is a language in progress and will continue to evolve over time. As it is much newer than Objective-C, Swift is likely to evolve at a faster pace.


Swift Pros and Cons

Does Swift have any limitations compared to Objective-C? In a word, yes. In particular, Swift only supports iOS7 and above. While this may not be a problem for many applications there is a small but persistent community of users who are still running iOS devices with versions lower than 7 installed. This number was hovering around 4% of all devices as of January 2015.

Generally, we have found that some enterprises have resisted moving to newer versions of iOS due to maintenance and compatibility concerns with their current portfolio of iOS applications.



Are there any other potential issues I should consider with Swift?

Being a new language, Swift does not have the same level of governance and guidance direction as the more established Objective-C. This may be acceptable for a single developer; however, for systems being created by multiple people a stronger level of internal team governance and review may be required to make sure the code structure is internally consistent within a given project or set of projects. In this way Swift is more like C#, JavaScript, or Java where there is less formal guidance on how code should be structured and problems solved.


If Swift is Apple’s new iOS development language, does that mean that Objective-C will be going away?

No, at least not in the near future. Apple still uses Objective-C in its internal projects. Given the comparatively short lifecycle of mobile applications, applications built today will be retired long before Objective-C reaches end of life.

It is not unusual for companies like Apple to maintain more than one application development language. For example, Microsoft currently maintains Visual C++, C#, VB.Net, F#, and other development technologies. The mere existence of a second language within a company like Apple does not necessarily indicate the removal of the first. What would be indicative, however, is if Apple stops updating Objective-C. If that occurs, our recommendation may change.


What are the advantages of using Swift?

Swift has advantages over Objective-C in both simplicity and language capabilities. For new developers Swift is easier to learn. For many of the same reasons—such as learning simplicity—enterprises write applications in C# instead of Visual C++ on the Microsoft stack, they may also choose to work with Swift over Objective-C on the iOS stack. That simplicity to learn does not mean Swift has fewer features; however, many advanced language constructs exist in Swift that do not exist in Objective-C. So not only is it easier to learn, once it is learned it gives access to some useful capabilities such as generics.


If I think I might transition from Objective-C to Swift or vice versa, is there anything I can do today to make this transition easier?

Starting with XCode 6.0 Apple added dynamic frameworks which allow you to create a collection of code and resources that can be used in multiple projects. With this capability, cross-project shared components could be written in one language and replaced with another at a later date. This is allowed because mixed language projects are also allowed, so it is conceivable to replace a class or collection of classes written in Objective-C with one written in Swift later. Having said that, care must be taken with this type of extensibility in mind. How you might ideally solve a problem in Objective-C may not be how you would best solve it in Swift. Replacing pieces of code piecemeal only works if the interface to that code is generally kept the same. For example, replacing a class in Swift that uses generics to one in Objective-C that does not may not be possible without substantial refactoring of the code that calls it. Does Swift vs. Objective-C change when I would consider using a hybrid technology like Cordova or near-native technology like Xamarin? Generally no. Technologies like Xamarin or Cordova are usually selected to solve crossplatform challenges or when there is already internal competency in .Net or JavaScript. The addition of Swift does not substantially alter that equation. However, it does lower the barrier to entry for new developers to learn cross-platform, true native languages. It is likely easier for such a person to pick up Swift and Java than it would be to pick up Objective-C and Java. While that probably still isn’t as easy as just learning .Net or the HTML5/CSS/JS stack, it lowers the bar far enough where this may be a viable option for more people than it has been previously.


Are there any performance implications?

When Swift was first released Apple mentioned some areas where Swift clearly outperformed Objective-C. However, it also found that in some areas Objective-C was faster than Swift. Since then Apple has done much to improve the performance of Swift. In some cases Swift 1.2 is now slightly faster than Objective-C. However, the difference is marginal between the two and will likely not be the key selection factor. [https://medium.com/@harrycheung/mobile-app-performance-redux-e512be94f976]



Does either language have any cross platform capabilities outside of the Apple Ecosystem?

Microsoft recently released news that you will be able to adapt and compile Objective-C applications to run on the Windows Phone 10 platform with ARM processors. Additionally, at WWDC 15 Apple announced that Swift as a language would be open source by the year’s end. This opens up speculation that sometime in the future Swift may be useful to create applications on platforms other than Apple’s.


When should I use Objective-C?

• You have a substantial internal competency with Objective-C
• You have a substantial portfolio of apps written in Objective-C and would like to keep your support footprint low
• You need to support applications that target iOS 6 and earlier
• You are interoperating with large amounts of existing Objective-C code
• Your team could benefit from the directive governance and guidance that exists around the Objective-C stack
• You plan on making mobile applications for iOS and Windows Phone, but not Android • You like pointers


When should I use Swift?

• You have substantial internal competency with Swift
• You have a substantial portfolio of apps written in Swift and would like to keep your support footprint low
• You are only working with iOS 7 and later
• You have developers who are new to the Apple development stack that you would like to start working in true native technologies as soon as possible
• You are interoperating with large amounts of existing Swift code
• Your team has strong internal governance and guidance practices
• You have no existing true native iOS applications or capabilities and want to keep costs as low as possible without sacrificing capability (In general, for enterprise applications, languages that are easier to learn and have advanced modern language features have had advantages in development speed and cost of maintenance on other stacks. There is no reason to believe that the Apple stack will deviate.)
• You dislike pointers


Conclusion Apple will likely support Objective-C and Swift for the near future as first class languages on the Apple stack. Companies with substantial investments in applications and capabilities using Objective-C may want to either stay with Objective-C or only move to Swift as part of a deliberate plan. Additionally, organizations that need to support iOS 6 and below should gravitate to Objective-C. Organizations with no existing or limited iOS true native code and capabilities may want to consider Swift. It will be easier to learn and offer more modern language features. Mobile technology decisions are complex and involve a constantly changing landscape, one which Magenic is uniquely qualified to help clients navigate due to our customized agonistic and diagnostic approach.


About the Author:

KevinFord

Kevin Ford is Practice Lead, Mobile Development in Magenic. Responsible for increasing the delivery capabilities in mobile technologies in Magenic's national mobile practice and Magenic's regional offices. With this comes a key role in growing and shaping our mobile practice through training and mentoring consultants, setting mobile technical direction, and bringing visibility to Magenic's mobile capabilities by being a community thought leader.


Magenic's mobile delivery capabilities include vendor native tools with Objective-C/Swift, Java and C#, Xamarin and Cordova. Magenic's mobile practice lead needs to be fluent in all of these and with that set the tone for how these technologies can be successfully leveraged to create mobile applications in the enterprise.

 

Don't have an account yet? Register Now!

Sign in to your account

Cron Job Starts