So you want to develop apps for iOS, but you're not sure whether to start learning Objective-C or Swift. We've been there, but luckily we had Bloc iOS mentor Steve Schauer to guide our decision.
In this webinar, you'll learn:
- The differences between Objective-C and Swift
- Which language is easier to learn and use to develop awesome apps.
- Exactly what you need to know to get started building for iOS.
- Plus, ask Steve your own questions about iOS development, Objective C, and Swift!
Ever since Apple released their newest programming language Swift, I get questions all the time from future bootcampers asking if they should be learning Objective-C or Swift. In this webinar, we’re going to answer that question with the help of Steve Schauer who has been an iOS developer for over 5 years. He’s also a lead mentor at Bloc, and he’s going to give us an overview of Objective-C and Swift and try to answer all of your questions.
We have a really great, exclusive scholarship for everyone who’s tuning in. Go through Course Report for your Bloc application and you’ll get $100 dollars off your tuition to your next apprenticeship.
So with that, let’s get started. I am going to share some of the slides that we’ve put together and Steve, why don’t you start by introducing yourself.
Hi, everybody. My name is Steve Schauer. I am the lead iOS mentor at Bloc.io online boot camp. As Liz mentioned, I’ve been an iOS developer for a while now and a software developer for a lot longer than that. I’m really having an awesome time at Bloc; it’s so fun to see people come in and learn a trade and get a job and do all these amazing things.
That’s a question that we hear all the time as well, is would I learn Swift or should I learn Objective-C? And so without going into an incredible amount of technical detail, we’re going to try and answer those questions.
Here are some of the things we hear about why people are excited about Swift and why they think this is a great time to jump in and learn it.
There are no developers with 5 years of experience with Swift. So if I start now, in 5 years I’ll be one of those people with 5 years of experience. There’s a lot to be said for that. People think back to when the iPhone was introduced. When the app store opened, it was commonly referred to as a gold rush. You could get just about anything there.
Another thing we hear all the time is it’s just easier to understand than Objective-C or C. It has some really great new language features.
And probably the biggest thing that I hear, it’s simpler. I don’t necessarily agree with that part but let’s take a look.
Objective-C has many decades of history behind it. It started in the 80s with Steve Jobs’ company, Next Computer Company. It was developed to be the development language for the Next Step operating system. And when he returned to Apple and OS-10 was developed, Objective-C was the development language for that and we’ve been using it ever since. It’s very well established, it’s a dynamic language, has amazing third party support because of the millions and millions of developers and users. You can search for a question if you’re having trouble with a development issue and there’s going to be so many answers, so many resources to go and find help.
Then we have Swift. Last year when that was announced, unlike most of the Apple events where we kind of know what to watch, this was just an absolute surprise for everybody. We have a brand new language, which doesn’t happen all that often.
It’s got a lot of safety features. One of the main design reasons for creating Swift was that there are a lot of common app crashing errors that happen in iOS apps and Swift was specifically designed to prevent a lot of those errors. It has typed in inference, which means that you don’t have to type as much. You can say something like this variable customer name = Smith. The compiler will figure out that’s a string.
It has Optionals which are a really powerful feature that prevents lot of common errors. You get into a situation where a method might need to return a valid value that is nothing or zero – like my bank account. Ask what the balance is it’s zero. But what happens if it really isn’t zero? There was an error, the bank burned down or there is no bank account, what are you going to do? Zero means something specific so commonly in Objective-C, in that case you return minus 1 as a signal that that didn’t go correctly so that you could reserve zero to be a value.
Well, Swift solves this by something called Optionals which may exist and may return a value and may not. Another feature is generis and I’ll show you an example of that in a bit, where you can use a template instead of a specific type. You can say that this is any type and write your code to do multiple things depending on the type of things it’s actually working with.
Then the playground which is very cool, which turns Swift into like, a scripting language; you type the code and you immediately see the results on screen so it’s great for playing around.
So let’s look at some typical code and like I said, won’t go into a lot of depth on this.
This is a sample of some Objective-C code. We have a class called NS string and the reason it starts with NS is because that dates back to a prefix that stands for ‘Next Step’. It’s a pointer so we have an asterisk and we call it my STR and we initialize it with this string ‘my name is’ and we end it with a semicolon. Then if we want to append something to it, we have another line of code contained within square brackets which is the syntax. The method is called string by appending string. Objective-C is very wordy; you see these amazingly long method names. We’re going to pass it a parameter that just happens to be my name there and end it with a closing square bracket, and of course never forget the semicolon.
Now in Swift, we get the same result by typing in the keyword ‘var’ for variable: My STR= my name is Steve Schauer. That’s really clear, that’s a clear win for Swift – and no semicolon. You can just think of all the time you’re going to save in your life without having to type all those semicolons.
There’s other parts where the differences are less apparent, the big gain in readability and/or amount of letters you have to type to initialize and declare an array. Again, it starts with NS; NS array, ‘my array’ and we pass it within these square brackets. So we’re going to have an array of three items. The first one is “Swift,” the second is “Array,” the third is “Dictionary.” In Swift, it looks very much the same and even has square brackets around it but once again, we don’t have to type the semicolon.
Next, this is some code that comes directly from one of our project examples. In a view controller there’s a method called view load for when you’re ready to go but you have not yet appeared on screen so you can do your setup work there. We’re calling it super view load, that’s our super class; let it get a chance to do anything it wants to do. The next four lines are creating a scroll view and adding that as a subview to our main view and we’re setting this back on colored white. We’re going to add an image and call it UI imageview new then we’re going to add that subview to our scroll view.
Now in Swift, unlike some of the earlier examples that we were looking at, it looks almost identical. Override and func, you did load and it has a couple of trailing parentheses which can contain a parameter and then those 6 lines of code are almost absolutely identical. And the reason that they are is that iOS itself is implemented through a collection of frameworks like iKit, Core Location and Core animation; those are all written in Objective-C.
So, when we’re working in Swift and when we’re working in the real world, a huge amount of our code involves stringing together and manipulating a series of calls into the Objective-C framework. That’s why Swift is really only superficially different than Objective-C. You don't have to remember to type a semicolon, you don’t have to have to have square brackets in most cases, you use the dot notation instead. This is the reality that a huge amount of code that you write as a developer is in a production setting.
Let’s talk a little bit more about some of the new features in Swift. There is something called a Tuple. In Objective-C and C, a method or function can return a value. In Swift, a method or function can return multiple values that are called Tuples. For example, I could have a method in Objective-C that returns a customer name and another method that returns an address and there’s ways to return both of those as a structure. In Swift I can write a method that would return the customer name and the address to separate returns.
There are some extremely powerful collection operators, map and join and filter.
Optionals, we talked about that and generics are the templates. These are a couple of simple Swift functions. We wanted a method that we would pass it two integers and it would compare them and returns which one was the largest of the two. It’s a function that that takes two integers as parameters and returns that the first is greater than or equal to second, return first and if not then it’s return second.
Now let’s say we want to do the same thing but this time it’s a double instead of an integer so we’ll write another method. And you look at those two; the only difference is the type of the return value and the type of the parameters. So with generic and Swift we can combine these two and we can have one method called Maximum Value. It takes a T or template and we’re saying it conforms to the comparable.
Comparable is the protocol. If you conform to that it means that you will understand greater than, less than, equal. It takes two parameters but those are type T. In other words, as long as that type that you’re passing in conforms to the comparable protocol, it’ll work so we don’t have to write two methods. In a simple case like that, that’s pretty darned cool.
In the next slide you can see how you can really go crazy with things like that. I don’t even want to try to explain what this line of code does. It’s doing a lot of powerful work.
There’s a famous statement but I’ve forgotten who said it: debugging is twice as hard as coding. So if you’re as clever as you can be while you’re coding, what’s going to happen when you try to debug something like that? The point of this scary-looking slide is that Swift is deceptively simple. It’s also got an amazing amount of new power that needs to be learned.
Another problem that we encounter working with Swift is that it’s a moving target. It’s not fully baked. This is a list of the methods that were either removed or added or changed between iOS 8.2 and 3.
You’ve got this extra added complexity. Did the language change underneath me? That’s a difficult thing to deal with when you’re trying to learn a lot of new concepts.
At Bloc, one of our samples is a game called Switris. It’s a cascading block game written in Swift and it has been updated 5 times since it was originally written.
The other big thing with Swift is what is your goal in learning iOS development? Let’s take a look at one of the job market job recruiting aggregation sites a couple of days ago and I looked for iOS on any area and it came back with 3119 open positions that they knew about and that they were recruiting for, for iOS.
I did the same search for Swift and came up with the grand total of 35. There’s not a lot of jobs. And it makes sense if you think…we’re in our 8th year of iPhone and it’s gotten crazy that the amount of apps that have been written and the app store volume. Every iOS app that was ever written up until last June was written in Objective-C. So, the working developers that are out there by and large are working with Objective-C Code and that’s where the market is, that’s where the jobs are.
You can see on this slide the volume and the way that it’s growing at a tremendous rate and had surpassed Hollywood U.S. box office revenues, which I think is an interesting comparison there. I’d like to see one more line on the graph that said the number of people in a movie theater that are using their iPhone!
Who should learn Swift first?
This is the meat of the webinar here. If you’re a hobbyist, if you take on new languages as something fun to do and learn a new language, absolutely; Swift is awesome. The guy that developed Swift, the lead developer Chris Laffner is no dummy. There’s a lot of amazing stuff in Swift. If you’re a bleeding edge enthusiast, you want to be the first like that guy that says “5 years from now I want to be the person that has 5 years of experience already” then Swift is for you.
Who should learn Objective-C first?
Well, we’re pretty clear at Bloc about this. New developers need to start with Objective-C. If you’re already a seasoned developer but you want to move into mobile development, you need to learn Objective-C. There’s a number of reasons for that and probably the number one reason is that iOS itself is written Objective C and every time you’re working with the system – which you are the majority of the time and the majority of the code that you’re going to write – you’re going to be dealing with Objective-C classes and methods with a slight Swift veneer on them.
Finally, probably the biggest reason that you would want to learn Objective-C first is getting a job. There are a small amount of Swift development positions available right now. If your goal is to be an independent developer and you’re going to hit the app store, one person team and you want to learn Swift rather than Objective-C that would work. But if you’re interested in the real world and you’re interested in being a well-rounded professional iOS developer, whether you want to code in Swift or not, you need to learn Objective-C first.
Who should learn both?
We think everybody should learn both. It’s pretty clear that Swift is the future, that at some point probably the situation will reverse and the majority of coding that’s done for iOS is going to be done in Swift, not in Objective-C. That time is a long ways off; It’s definitely not happening this year, it’s definitely not happening next year. But more and more there are code samples that you see, there’s communities that are springing up. It’s great to learn but when you come at it with a solid basis with Objective-C, you’ll find that your life writing Swift code is going to go much smoother.
I’ve got a question from Marias. She says: Steve, would you recommend writing a watch app in Objective-C or in Swift?
I would recommend either of those. I think you could do it. There’s not a lot of code. They don’t do a whole lot yet. I think that would be a great project if you wanted to dive into Swift. Our course at Bloc starts with a foundation phase and then you move on to the project phase where you build apps and we have project specifications. One of them is an app in Swift with a watch app with it.
In our course, while the foundation is almost completely Objective-C, we do teach the basics of Swift. At the point where you begin the projects, it’s your choice whether you want to develop those in Swift or Objective-C. If your goal really is to learn Swift and deep dive into it, then our course can be as much as about 70% Swift and 30% Objective C.
Could you choose a mentor with Bloc who has a lot of experience with Swift or has a lot of experience with the documentation?
Absolutely. We try to match students with a mentor who has experience in what they’re most interested in. None of us are at that 5-year point with Swift but we do have mentors that have spent more time with it than others and are more excited about it. So, if that was your goal, absolutely; we would match you with someone who could really dive into Swift.
Liam says: I’ve been studying a little bit of Objective-C; I’m not an expert yet. Do I need to learn Objective-C before I start learning Swift or can I get away with starting Swift without having a solid grasp of Objective C?
We’re pretty clear that you need to learn Objective-C first and that’s how our course is designed. If you’ve done some development in the past in Objective-C, you’re going to be able to move through that portion pretty quickly and get on to the more fun stuff.
Can you tell us what Cocoa is and why it’s so important and if developers use it just with Objective-C or if they use it also with Swift?
Cocoa replaced Carbon on the Mac. Don’t quote me entirely on this but I think it’s the general term for the UI frameworks that are used to develop an OS10 or an iOS app. Cocoa was the environment that you used on the Mac and then when the iPhone was released, the modifications that were done to that base were called Cocoa Touch.
You mentioned during the comparison between Objective-C that Objective C has a really strong community. Have you noticed the community in the documentation like on Stack Overflow presence of it increasing pretty rapidly?
I have. There’s a lot more content today on Stack Overflow that’s Swift related than there was even three or four months ago so yeah, that community is definitely growing.
Julie has a question for us: It looks like Swift is easier to write and read. Is the language easier to learn than it is to learn Objective-C or are they about the same?
When you learn the basics of programming, that syntax, for an experienced developer to say “I want to learn a new language”, the syntax is not even the tip of the iceberg; it’s the top part of the tip of the iceberg. The frameworks that you use are the big hurdle that you need to learn.
Everybody loves the string example, ‘my name is + Steve Schauer’ because that is so much simpler; that one’s the best. The reality is that Swift has got a lot of complexities that don’t exist in Objective-C. The basic syntax is simpler. In some cases like in that string example, way simpler, but I don’t buy into the idea that Swift is simpler to learn than Objective-C.
How often does Bloc update the Swift and Objective-C curriculum – and the Objective-C curriculum to a certain extent as well?
That’s a great question. We’ve got a curriculum team that that’s what they do full time, is work on our curriculum in addition to iOS; we’ve got some other areas that we cover.
We’re rolling around to another Apple Worldwide Developers Conference in June. The invites just went out last week. Inevitably there’ll be some more big changes; just maybe not as big as last year. Last year was crazy.
We’ve got to keep our Swift sample code up to date with the new releases and we’ve got to move with the new operating systems releases and the new features. This last year we got extensions, we got a watch kit recently in addition to Swift, we got continuity There were a huge amount of changes in iOS8 so we probably won’t see as big a release this year.
If someone’s goal is to program for iOS, what’s the next step? Should they run out and sign up for Bloc, go to a meetup first? What do you suggest?
If you’re absolutely brand new to programming then at Bloc we point you at some pre-work that you can do, some research that you can do to prepare yourself to get a good running start. You can go to our website at Bloc.io and find the information for iOS.
Meetups are a great resource. There’s a lot of content. There’s a lot of ways that you can dip your toe in. All the time we accept new apprentices that have absolutely no programming experience and they complete our course. We’ve got success stories to show that it works.
We have a question from Erin: If you are saying that Swift is actually using a lot of Objective-C or looks like Objective-C in a lot of ways, then wouldn’t being a Swift developer make someone relevant as an iOS developer for a job? Are they actually that similar?
They’re pretty similar but the point I was trying to make is that the reason they look so similar is because that sample code in Swift was culling into Objective-C frameworks so they have the same names, the same parameters whether you’re writing them in Objective-C or Swift.
But if you get a job on a team that has an existing iOS application, they’re not going to say, “Well why don’t you go ahead and write your part in Swift?” Their existing code is all in Objective-C. Maybe they’ll make a decision at one point or another to develop a new feature in Swift or a complete rewrite. Generally, it takes a long time for something like that to happen. They’ve got to think about the return on investment like am I going to sell more copies of this application if it was written in Swift? Would Swift give me abilities that I don’t get in Objective-C? I think that’s a tough decision and most companies would probably say, “We already bought that code. Let’s just maintain that for a while longer and see how that goes.”
So Steve, do you have anything else that you want to share with us about your teaching approach at Bloc? Any last parting words?
Well, thanks for doing this, Liz. This has been fun. I hope it’s been informative. I love Bloc. I’m having just the best time working there and I love teaching the craft of development which is our philosophy at Bloc. We’re all about craftsmanship; practical instruction from experienced professionals that have been in the business. For the most part, the apprentices that come into Bloc, their goal is to be employed as a developer so that’s our mission and that’s a pretty fun thing to do.
I think what we’ve learned from this webinar is if you’re trying to decide between Objective-C and Swift, the answer is learn Objective-C if you want a job today and make sure that you tack on Swift if you want a job in the future.
Remember that you can use the Course Report code in the referral section of your Bloc application to get $200 off tuition because we want you to take that first step into learning web and mobile development. And of course, sign up for the Course Report newsletter on coursereport.com. You can get alerts about our next webinar and let us know what topics you want to see as well and we’re happy to host them.
Episode 18: September 2017 Bootcamp News
Read or listen to our September 2017 roundup of news and trends in the coding bootcamp industry.
Episode 17: August 2017 Bootcamp News
Read or listen to our August 2017 roundup of news and developments in the coding bootcamp industry.
Episode 16: July 2017 Bootcamp News
Read or listen to our July 2017 roundup of news and developments in the coding bootcamp industry.