Bummer! You must be logged in to access this page.

Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Swift

Ok so I've been making an app with objective c. I don't want to restart. What do I need to do to incorporate swift into my code?

Thanks so much.

2 Answers

Hello Jack,

Swift and objective-c work together very well, the way you use objective-c in swift (and vice versa) is to simply import the class you need set up a bridging header and start working. here is a good tutorial on how to do it, in it they go over unwrapping variable, this is a big deal because in swift object can't be nil (unless it's an optional) so you need to check if you can get out its value, they also go over bridging headers and how to move code around between the languages, how to be a swift delegate from an objective-c protocol, converting objective-c methods to swift and more.

anyways this is a good skill because for example let's say I'm making a music app and a really cool music player library is in swift and I want to use it my existing objective-c code base, I'll need to learn how to do this (and of course learn swift). any ways that fake scenario above isn't really fake, it happened to me and was more or less my motivation to learn swift (but funny story, I never used the library :P ).

any ways, you can always google how to do something like this and get good result.

Good luck, Kai

Thanks for posting this Kai Aldag. It would be great to see Team Treehouse put out a course on this. It's a pretty confusing topic if you don't have a project sitting in front of you. I also think doing something like this makes the Treehouse members learning Swift more valuable as devs because they can work with the ObjC codebase that exists in all Apple apps.