In the swift language, there are many encapsulation classes that do not, and if needed, need to bridge the classes in the OC language, then you need to use the bridge header file, which is the step to use:
Create a swift project demo, and then build a new OC language file
Create a Bgimgview class, select the corresponding Object-c language, click the Next button
A prompt will pop up asking if you need to configure a bridge header file, click the Create button (the third one)
A bridge header file is automatically generated at this time
Now start adding the relevant code in the OC file that you need to use
. h file
{
ID _targett;
SEL _selt;
}
Number of rows without parameters
-(void) Testt;
Parameters to return
-(NSString *) nameStr;
Add a Click event method to mimic the click of a button
-(void) AddTarget: (ID) targettt withselector: (SEL) SELECTT;
. m file
Number of rows without parameters
-(void) TESTT
{
NSLog (@ "called the Testt Method .... ");
}
Parameters to return
-(NSString *) nameStr
{
Return @ "Study hard, day up";
}
Add a Click event method to mimic the click of a button
-(void) AddTarget: (ID) targettt withselector: (SEL) SELECTT
{
_targett = TARGETTT;
_selt = SELECTT;
Whether to interact
self.userinteractionenabled = YES;
}
-(void) touchesended: (Nsset<uitouch *> *) touches withevent: (Uievent *) event
{
if (_targett)
{
[_targett Performselector:_selt withobject:self];
}
}
After writing the required code, you need to add a header file in the bridge file, only the OC header files that need to be used, do not need to write all the OC files
And then in. Used in Swift files,
Create a Bgimgview object
Let BGIMGV = Bgimgview.init (Frame:cgrectmake (10, 100, 200, 100));
Bgimgv.image = Uiimage.init (named: "22.jpg");
Calling methods
Bgimgv.testt ();
Return Parameter method
Let nameStr = Bgimgv.namestr ();
NSLog ("Output ... %@ ", NAMESTR);
Add a Click event
Bgimgv.addtarget (Self, Withselector: #selector (Viewcontroller.imgclick));
Self.view.addSubview (BGIMGV);
}
Func Imgclick (Imgv:bgimgview) {
NSLog ("Click on the picture ..... ");
}
Final output effect:
Swift Foundation calls OC language files using steps