![]() It may look like this (I’ll leave out all the properties and methods this class may have): ![]() Let’s assume our Swift class is a UIViewController. That’s all we have to do in Xcode for now. We’re looking for an option called Embedded Content contains Swift Code (under Build Options): To do this, head over to your target and find the Build Settings tab. We’ll also need to tell it that we want to use both Swift and Objective-C in the same project (as if that wasn’t obvious). You’d think this is all the information our clever Xcode should need, but it isn’t. make Objective-C code usable in Swift.Īgree to the friendly offer anyway, so both classes can access each other natively. ![]() Technically we don’t need this: it will be useful to do the reverse of what we want to do, i.e. Preparing your Xcode ProjectĪs soon as we add a Swift class to an Objective-C project, we’ll get an invitation from Xcode: “Shall I create a Bridging Header” it asks. I’m assuming we have a project written in Objective-C, but there’s a new Swift class that needs to be used and we want to access it from Objective-C code, with Objective-C syntax. ![]() It is possible to use Swift classes from Objective-C code (and vice versa) – but Apple’s documentation is a little cloudy (and verbose) on how to actually achieve this magic.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |