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: