Mixed compilation of oc and swift, and mixed compilation of ocswift

Source: Internet
Author: User

Mixed compilation of oc and swift, and mixed compilation of ocswift

Reference: http://blog.sina.com.cn/s/blog_8d1bc23f0102v5tl.html

Methods Using oc classes in swift

1. Create an oc. h file

 

2. Add the header file of the oc class to be imported.

3. Search for bri in Bulid Settings and add: $ (SRCROOT)/$ (TARGET_NAME)/oc. h.

 

4. Test

Test. h

# Import <Foundation/Foundation. h>

@ Interface Test: NSObject

-(Void) test;

@ End

Test. m

# Import "Test. h"

@ Implementation Test

-(Void) test {
NSLog (@ "this is a test ");
}

@ End

ViewController. swift

Import UIKit

Class ViewController: UIViewController {

Override func viewDidLoad (){
Super. viewDidLoad ()

Var test: Test? // Statement
Test = Test () // Initialization
Test ?. Test () // CALL THE METHOD
}

Override func didReceiveMemoryWarning (){
Super. didReceiveMemoryWarning ()
// Dispose of any resources that can be recreated.
}

}

Print Information:

 

 

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.