The –Swift call OC iOS mixed

Swift creates projects that want to call OC relatively easily, just import the OC class you want to call in the bridge file.

when creating the Swift project in the OC class, the system will prompt whether we create a bridging file, this time we must choose to create, or we need to create your own path set

The --Swift call OC iOS mixed
creates bridge files
The --Swift call OC iOS mixed
bridge file directory

Create properties and methods in the OC class.
note: if you want to be called outside, write it in.H. This is the OC feature

.h file #import < Foundation/Foundation.h> @interface OCClass: NSObject @property (nonatomic, copy) NSString *name; - - (NSString *) sayHello: (NSString *) name; @end
The.M file #import "OCClass.h" @implementation - OCClass (NSString *) sayHello: (* NSString) name{return [NSString stringWithFormat:@ "say name]% @ Hello, @end};

In the created bridge header file, you include the OC class you want to be called

The --Swift call OC iOS mixed
Snip20170604_15.png

Since Swift does not need to include header files, it is OK to call OC directly in Swift

Import UIKit class ViewController: UIViewController override func (viewDidLoad) {{super.viewDidLoad (let) = OCClass (ocClass); let STR = ocClass.sayHello ("CF"); print (STR!); ocClass.name = "CF"; print (ocClass.name)}}
The --Swift call OC iOS mixed
print results