Ios-oc, Swift mixed bridge file

Source: Internet
Author: User

Create a new OC language project, and then add a NSObject-based Swift file Swiftfilemodel class

. Swift

Import UIKit class Swiftfilemodel:nsobject {func firstmethod () {print ("swiftfilemodel");}}

You will be prompted to add a bridging file, click Create after the decency will automatically create a bridge file, but if you click Cancel, you need to build a bridge file;

To create a bridge file manually

New h file, name casually, but the best professional, I'm not professional here

Then go to build Settings search Brid, find objctive-c bridging Header, the bridge file just built to drag directly into, will automatically refer to the path;

Here the bridge to the file and configuration is OK;

Swift calls OC

Create a new NSObject-based OC file Ocfilemodel class

. h

#import <Foundation/Foundation.h>@interface  ocfilemodel:nsobject+ (void ) Oclog; @end

. m

#import " OcFileModel.h " @implementation Ocfilemodel+ (void) oclog{    NSLog (@ "ocfilemodel" );} @end

Add the Ocfilemodel header file #import "OcFileModel.h" to the bridge file

Implementing the Call Oclog method in the Swiftfilemodel.swift class

OC Calls Swift

Ios-oc, Swift mixed bridge file

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.