Ways to use OC/C in Swift projects

Source: Internet
Author: User

If there is a OC class Ocviewcontroller:uiviewcontroller
There are two methods in the class

Swift calls to OC or C's mash-up are more commonly used, and in turn few calls are made. This only writes the way Swift calls OC and C.
OC Function Declaration
-(void) Testoc;
C function Declaration
void Testc ();

Realize:
void Testc ()
{
printf ("Testc .............");
}

-(void) Testoc
{
NSLog (@ "\ntestoc ..............)");
}

Adding the OC class to the SWIFT project, the system automatically generates an. h file named: Project name-bridging-header.h

Introduce the header file of the Oc/c class in this area
#import "OCViewController.h"

So you can use it directly.

Class Viewcontroller:uiviewcontroller {
Override Func Viewdidload () {
Super.viewdidload ()
Instantiating classes
var OCVC = Ocviewcontroller ()
Swift calls OC function
Ocvc.testoc ()

Swift calls the C function directly
TESTC ()

Additional setup after loading the view, typically from a nib.
}
}

Ways to use OC/C in Swift projects

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.