swift语言混编--语言交互的接口
FFI stands for Foreign Function Interface. A foreign function interface is the popular name for the interface that allows code written in one language to call code written in another language.
https://www.cnblogs.com/feng9exe/p/10396004.html
-Bridging-Header.h
Alternatively, you can create a bridging header yourself by choosing File > New > File > [operating system] > Source > Header File.
in Swift Compiler make sure the Objective-C Bridging Header build setting has a path to the bridging header file.
Any public Objective-C headers listed in the bridging header are visible to Swift. The Objective-C declarations are automatically available from any Swift file within that target, with no import statements.
Import Code Within a Framework Target
To use the Objective-C declarations in files in the same framework target as your Swift code, you’ll need to import those files into the Objective-C umbrella header—the master header for your framework. Import your Objective-C files by configuring the umbrella header:
- Under Build Settings, in Packaging, make sure the Defines Module setting for the framework target is set to Yes.
- In the umbrella header, import every Objective-C header you want to expose to Swift.
Swift sees every header you expose publicly in your umbrella header. The contents of the Objective-C files in that framework are automatically available from any Swift file within that framework target, with no import statements.
-Swift.h
Objective-C generated interface name header
This file is an Objective-C header that declares the Swift interfaces in your target, and you can think of it as an umbrella header for your Swift code. You don’t need to do anything special to create the generated header—just import it to use its contents in your Objective-C code.
By default, the generated header contains interfaces for Swift declarations marked with the public or open modifier.
The Swift interfaces in the generated header include references to all of the Objective-C types used in them, so make sure to import the Objective-C headers for those types first.
Import Swift code into Objective-C within the same framework:
- Under Build Settings, in Packaging, make sure the Defines Module setting for that framework target is set to Yes.
- Import the Swift code from that framework target into any Objective-C .m file within that target using this syntax and substituting the appropriate names:
#import <ProductName/ProductModuleName-Swift.h>
Swift3.0 调用C函数-_silen_name
创建.swift文件,引用.c文件函数
// 在全局作用域下进行声明
// swift 2.2使用关键字@asmname
import Foundation
@_silen_name("add") func c_add(_ num1: Int, _ num2: Int) -> Int
@_silgen_name("mul") func c_mul(_ num: Int, _ times: Int) -> Int
// 调用函数
print(c_add(90, 23))
print(c_mul(3, 20))
但从长远来看,Swift应该会很快集成一个FFI之类的功能以便于和其他语言/库集成,同时性能优化和对语言中的小问题做修正,完全代替Objective-C应该是在Apple的计划当中的,话说已经有那么多人为了Apple学了Objective-C,再多学一门语言也不是什么事儿。
https://segmentfault.com/q/1010000000533328
swift语言混编--语言交互的接口的更多相关文章
- python和C语言混编的几种方式
Python这些年风头一直很盛,占据了很多领域的位置,Web.大数据.人工智能.运维均有它的身影,甚至图形界面做的也很顺,乃至full-stack这个词语刚出来的时候,似乎就是为了描述它. Pytho ...
- Swift & OC 混编 浅析
转载自:http://www.infoq.com/cn/articles/wangyi-cartoon-swift-mixed-practice?utm_campaign=rightbar_v2&am ...
- 在Swift中实现 oc与swift的混编
在Swift中想要引用OC头文件(import),可采用混编的方法,这里以sqlite为例,采用OC-Swift桥的方式实现添加头文件1引入sqlite数据库的库文件 打开工程配置文件,在build ...
- swift objective-及c语言 混编
在xocde6出来我们大部分代码都是用objective-c写的(部分C/C++),现在出生来了一个新的语言叫swift,那么如何既能使用我们之前的代码,还可以使用新语言呢, 本文就此做一下说明. 关 ...
- iOS开发之OC与swift开发混编教程,代理的相互调用,block的实现。OC调用Swift中的代理, OC调用Swift中的Block 闭包
本文章将从两个方向分别介绍 OC 与 swift 混编 1. 第一个方向从 swift工程 中引入 oc类 1. 1 如何在swift的类中使用oc类 1.2 如何在swift中实现oc的代理 ...
- Java与groovy混编 —— 一种兼顾接口清晰和实现敏捷的开发方式
有大量平均水平左右的"工人"可被选择.参与进来 -- 这意味着好招人 有成熟的.大量的程序库可供选择 -- 这意味着大多数项目都是既有程序库的拼装,标准化程度高而定制化场景少 开发 ...
- object-c 混编 调用C,C++接口
xcode 支持 object-c 混编,在object-c 中调用c,c++接口 第一步 定义c语言 接口(File.c) #include <stdio.h> void printsB ...
- cocoapod Podfile use frameworks swift/oc混编 could not build module xxx
前置: 知名的pod: AFNetworking 我自己的pod: AFNetworking+RX 3.1.0.18 里面有一段代码是: #import <Foundation/Founda ...
- oc和swift的混编
参考:http://blog.sina.com.cn/s/blog_8d1bc23f0102v5tl.html swift中使用oc类的方法 1.创建一个oc.h文件 2.添加需要倒入的oc类的头文件 ...
随机推荐
- [转]git操作指南
[GIT上手篇]-1-基本操作(初始化仓库,添加.提交文件) 创建(初始化)一个GIT库 init 命令 说明:用于仓库的初始化 参数:--bare 创建一个纯仓库(不含缓存区和工作目录,服务器一般采 ...
- [转]JS实现千分位
本文转自:https://www.cnblogs.com/lvmylife/p/8287247.html 方法一:正则实现 function format (num) { var reg=/\d{1, ...
- spring cloud config与eureka配合使用
前面两篇介绍了Spring Cloud Config服务端和客户端的简单配置,本篇介绍Spring Cloud Config与Eureka配合使用 前言 默认情况下,配置客户端启动时,都是通过配置属性 ...
- soapUI工具使用方法、简介、接口测试
一.soapUI简介 SOAP: WebService通过Http协议发送请求和接收结果时,发送的请求内容和结果内容都采用XML格式封装,并增加了一些特定的HTTP消息头,以说明HTTP消息头的内容格 ...
- 2、买卖股票的最佳时机 II
2.买卖股票的最佳时机 II 给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格. 设计一个算法来计算你所能获取的最大利润.你可以尽可能地完成更多的交易(多次买卖一支股票). 注意:你不能 ...
- 【Spring】15、spring mvc路径匹配原则
Ant path 匹配原则 在Spring MVC中经常要用到拦截器,在配置需要要拦截的路径时经常用到<mvc:mapping/>子标签,其有一个path属性,它就是用来指定需要拦截的路径 ...
- 【读书笔记】iOS-配件
如果你想用External Accessory框架开发第三方硬件设备,你需要考虑成为Made for iPhone(MFI)授权项目的成员. 得到授权的开发者可以获取技术资料,硬件设备以及技术支持,以 ...
- 关于jQuery出现的新添加元素点击事件无效
//通常点击写法: $(".div").on('click', function () { var $this = $(this); var isActive = $this.ha ...
- Salesforce 数据库操作简介
Salesforce 中的数据库操作方式 Salesforce 为用户和开发者提供了四种基本的数据库操作方式: Apex 中的 DML 语句 Apex 中的 Database 类 SOQL 查询 SO ...
- Expo大作战(三十)--expo sdk api之Permissions(权限管理模块),Pedometer(计步器api)
简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人 ...