1. First create obj-c/Swift project
2. Create the Swift/obj-c file, which is where Xcode prompts you to create a bridging file between Swift and Obj-c, and click Confirm.
3. In the production xxx-bridging-header.h, import the files that need to be used in swift.
4. Calls can be made using Swift's syntax in swift files
Example:
Objective-c (abc.h)
+ (NSString *) Strbyswift;
Called in Swift
Abc.strbyswift ()
NOTE * * *
Xcode automatically converts the OC method to use in Swift, with the same method name.
Methods for calling Swift in Obj-c
1. target-"Build Setting->package defines module must be set to YES,PRODUCT module name set to XXX, default to project name, do not modify
2. In the obj-c file that needs to be called, import the header file "Xxx-swift.h", XXX for the previous set module NAME.
3. Use OC syntax in OBJ-C code to invoke the method inside Swift
Example:
Swift
Class Swifttest:nsobject {func swiftstr ()->nsstring {return ' Swift string '}}
Called in Objective-c
Swifttest *swifttest = [[Swifttest alloc] init]; [Swifttest SWIFTSTR];
Objective-c and Swift