首页 技术 正文
技术 2022年11月18日
0 收藏 770 点赞 3,606 浏览 2512 个字

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:

  1. Under Build Settings, in Packaging, make sure the Defines Module setting for the framework target is set to Yes.
  2. 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:

  1. Under Build Settings, in Packaging, make sure the Defines Module setting for that framework target is set to Yes.
  2. 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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,903
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,429
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,245
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,057
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,689
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,726