Chapter 10. Harnessing the Past – Understanding and Translating Objective-C

While Apple's platforms have been around for many years, Swift is still a very new language. Even before the release of the first iPhone, Apple's primary language of choice was Objective-C. This means that there are a vast number of resources in the world for developing on Apple's platforms using Objective-C. There are many amazing tutorials, code libraries, articles, and more, that are written in Objective-C that are still incredibly valuable for a Swift developer.

To take advantage of these resources, you must have at least a basic understanding of Objective-C, so that you can translate the concepts learned in tutorials and articles into Swift, as well as make use of the time tested Objective-C libraries.

In this chapter, we will develop a basic understanding of Objective-C with a focus on how it compares to Swift with the following topics:

  • Swift's relationship to Objective-C
  • Background of Objective-C
  • Constants and variables
  • Containers
  • Control flow
  • Functions
  • Types
  • Projects
  • Calling Objective-C code from Swift

Swift's relationship to Objective-C

As we discussed already, Objective-C was previously the primary language for developing on Apple's platforms. This means that Objective-C had a lot of influence on Swift; the largest of which is that Swift was designed to interoperate with Objective-C. Swift code can call Objective-C code and, likewise, Objective-C code can call Swift code.

Ultimately, Swift was designed, and is still is being designed, to be the next step in programming languages, without having to throw away all of our Objective-C code. Apple's stated goals for the language are for Swift to be more modern, interactive, safe, fast, and powerful. These words would be pretty much meaningless if we didn't already have a baseline to compare Swift against. Since Swift was designed primarily for Apple's platforms, that baseline is largely Objective-C.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset