Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/mobile: Exported structs not retaining field values in Swift #32008

Open
triztian opened this issue May 13, 2019 · 1 comment

Comments

Projects
None yet
3 participants
@triztian
Copy link

commented May 13, 2019

What version of Go are you using (go version)?

$ go version go1.12.4 darwin/amd64

Does this issue reproduce with the latest release?

Haven't tested

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN="/Users/tristian/go/bin"
GOCACHE="/Users/tristian/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/tristian/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.4/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.4/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/g1/v3hz1sm92nv7wbzpg3dx_h_h0000gp/T/go-build064001605=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I'm using the latest gomobile, installed from this commit:

commit 32b2708ab17190067486adc3513cae8dc2a7e5a4 (HEAD -> master, origin/master, origin/HEAD)
Author: Mark Villacampa <m@markvillacampa.com>
Date:   Thu May 9 10:20:13 2019 +0000

In my go source, I added a struct type that is exposed as part of Gomobile:

type Config struct {
  OSName string
  OSDevice string
}

// NewConfig()
func NewConfig() *Config { 
  return &Config{}
}

In the Swift code I use the following to create an instance and set some fields.

// "Mobile" is the prefix package name
// var config = MobileNewConfig() (tried this too)
let config = MobileNewConfig()

config?.osName = "some name"
config?.osDevice = "some string"

I build the framework like so:

GO111MODULE=off gomobile bind -a -v -target=ios/arm,ios/arm64,ios/amd64 example.com/mobile

What did you expect to see?

I expected to see the config variable retain the assigned string values in the swift code.

What did you see instead?

The config variable not retaining the swift values, for example take a look at this debugger capture:

Debugging

@gopherbot gopherbot added this to the Unreleased milestone May 13, 2019

@gopherbot gopherbot added the mobile label May 13, 2019

@triztian

This comment has been minimized.

Copy link
Author

commented May 14, 2019

I've created the following repo to reproduce the issue:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.