Join Simon Allardice for an in-depth discussion in this video Adding Swift to an existing Objective-C project, part of Comparing Swift and Objective-C.
- I'm beginning with an Objective-C project here.…This is just a standard command line tool application.…I've added a single custom Objective-C class…called vehicle with some stright forward properties…type, year, numberofwheels.…I have one bit of implementation that just…returns a descriptive message,…and in my main.m,…I've just got some straight forward codes…to instantiate one object of that class.…This is all Objective-C, there's no Swift in here at all.…I want to start mixing and matching.…If I just wanted to create a new Swift class from scratch…in this Objective-C project,…I could certainly do that just using the standard file menu.…
Just go to file, new file, and add a Swift file.…There's nothing that would stop you to do that.…I do have a player.Swift class conveniently…written in a separate folder here.…I want to bring that into my Objective-C project.…Now, when you're adding files to X code,…you have quiet a few different options.…I personally found that the classic…add files to Objective-C Project,…
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