Join Simon Allardice for an in-depth discussion in this video What you should know, part of Comparing Swift and Objective-C.
- This isn't a course about the basic syntax of either Swift or Objective-C. I've recorded plenty of that already. If you haven't touched Swift at all, I would suggest you go through the first few chapters of Swift Essential Training here are lynda.com. On the other hand, if you have no idea what square brackets represent in Objective-C, take a look at the first few chapters of Objective-C Essential Training. You don't need to an expert in both languages, but you should be able to read simple code. Because while these courses, not surprisingly, focus on each specific language, here is where we explore the crossover.
What happens when these two languages meet? We will do direct comparison between Swift and Objective-C syntax. I'll review instantiating objects, calling methods, working with strings and collections, and more. But what I won't be talking about are things like the difference between using var and let in Swift, or that a string literal in Objective-C has an "at" sign at the front of it. So if you need to brush up on either Swift or Objective-C concepts or syntax, use those courses as a resource that you can jump in and out of as you go through this one.
But why should you care about this course? Even if you're all about the new hotness of Swift and you're intending never to write a line of Objective-C, you're going to see it for awhile. We have so many years, so much legacy of Objective-C with IOS and Mac development, that when you have a problem and start searching the web for suggestions, you're going to find Objective-C sample code, you're gonna see answers on stack overflow that are perfect except they're written in Objective-C, and you'll need to be able to translate those into Swift. And a lot of the patterns and practices that have been built up over the years come from Objective-C, and you'll understand what we do in Swift a lot better if you understand a little bit more about Objective-C itself.
And, conversely, if you've been writing Objective-C for years and you're totally happy in that world, well, then, you'll have been doing Apple development long enough that you know how Apple do things. So you already know you won't be able to avoid Swift going forward. There are features in this language that Objective-C simply can't do, and it's how we're building Apple development from this point on. But with the basic syntax of both languages, let us begin here with some explicit comparisons between the two. And we're going to start by understanding that the way Swift and Objective-C interact with each other is not a level playing field.
Need a refresher on either language? Check out Swift Essential Training and Objective-C Essential Training.
- Exploring the interoperability of Swift and Objective-C
- Comparing language syntax
- Understanding how each language uses objects and methods
- Bridging arrays, dictionaries, and numbers
- Dealing with nil return types from Objective-C methods
- Working with NSError in Swift
- Working with Swift and Objective-C strings
- Adding Swift to an existing Objective-C project
- Inheriting between languages