Create a new OC language project, and then add a NSObject-based Swift file Swiftfilemodel class
. Swift
Import UIKit class Swiftfilemodel:nsobject {func firstmethod () {print ("swiftfilemodel");}}
You will be prompted to add a bridging file, click Create after the decency will automatically create a bridge file, but if you click Cancel, you need to build a bridge file;
To create a bridge file manually
New h file, name casually, but the best professional, I'm not professional here
Then go to build Settings search Brid, find objctive-c bridging Header, the bridge file just built to drag directly into, will automatically refer to the path;
Here the bridge to the file and configuration is OK;
Swift calls OC
Create a new NSObject-based OC file Ocfilemodel class
. h
#import <Foundation/Foundation.h>@interface ocfilemodel:nsobject+ (void ) Oclog; @end
. m
#import " OcFileModel.h " @implementation Ocfilemodel+ (void) oclog{ NSLog (@ "ocfilemodel" );} @end
Add the Ocfilemodel header file #import "OcFileModel.h" to the bridge file
Implementing the Call Oclog method in the Swiftfilemodel.swift class
OC Calls Swift
Ios-oc, Swift mixed bridge file