#必要条件
go语言环境
gomobile
Xcode
#go语言代码 保存路径:golang.org/x/mobile/example/bind/hello/hello.go
package hello
import "fmt"
func Greetings(name string) string {
return fmt.Sprintf("Hello, %s!", name)
}
#对go代码进行封装
1 获取代码path
$ go get -d golang.org/x/mobile/example/bind/hello
2 进行集成封装
$ cd $GOPATH/src/golang.org/x/mobile/example/bind
$ gomobile bind -target=ios golang.org/x/mobile/example/bind/hello
此命令在hello路径下生成Hello.framework
#在Xcode中集成Hello.framework
打开新建工程Go_iosTest
拖拽hello.framework文件到xcode项目内
在需要的地方#import "Hello/hello.h"引入头文件
HelloGreetings(@"") 调取go模块方法并传递参数