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: ObjC: binding callback #25847

ensoreus opened this issue Jun 12, 2018 · 2 comments

x/mobile: ObjC: binding callback #25847

ensoreus opened this issue Jun 12, 2018 · 2 comments


Copy link

@ensoreus ensoreus commented Jun 12, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.10.1 darwin/amd64

Does this issue reproduce with the latest release?

not sure

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

GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/_t/3lgmn1p93kng76718p0hkqh80000gn/T/go-build992461229=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I have a Go interface
type GetResponse interface { OnResult(json string) }

I have to subscribe on that event OnResult from ObjC using this interface.
func Subscribe( response GetResponse){ response.OnResult("some json") }

ObjC bind gives me a corresponding protocol and a basic class
@interface GetResponse : NSObject <goSeqRefInterface, GetResponse> {
@Property(strong, readonly) id _ref;

So, I need to get this json in my ObjC env. How can I do that?

Subclassing If I subclass this GetResponse or just use it as is and pass to Subscribe routine, it crashes
'go_seq_go_to_refnum on objective-c objects is not permitted'
Category if I create struct on Go side with the protocol support, I can't subclass it but at least it's not crashes:
type GetResponseStruct struct{} func (GetResponseStruct) OnResult(json string){log.Info("GO RESULT")} func CreateGetResponse() *GetResponseStruct{ return &GetResponseStruct{} }
I have a solid object without obvious way to hook up my callback. If I make a category and override the onResult routine, it's not called. Just because overriding existing methods of class is not determined behavior according to AppleDoc. Anytime OnResult called from Go, the default implementation invokes and "GO RESULT" appears.
Swizzling I tried to use category and swizzle (replace method's implementation with mine renamed method) but it only works if I call onResult from ObjC env.

What did you expect to see?

I expect to see the #1 way working (with subclassing), with no crash.

What did you see instead?

it crashes
'go_seq_go_to_refnum on objective-c objects is not permitted'

Copy link

@bcmills bcmills commented Jun 12, 2018

I can't parse this report. Is this a problem you encountered when using the gomobile tool? Is this a bug report, or a general question?

If this is a bug report, please include a link to a complete program and the commands used to build it, if possible. (Also see for examples of how to format code in GitHub issues.)

We generally prefer golang-nuts for questions, or see for other venues.

@bcmills bcmills added this to the Unreleased milestone Jun 12, 2018
Copy link

@ensoreus ensoreus commented Jun 12, 2018

yes, it's gomobile
I think it's a bug if you have no answer on that presumably "general question".
Commited the "question" on StackOverflow with "go" tag.

@FiloSottile FiloSottile changed the title ObjC: binding callback x/mobile: ObjC: binding callback Jul 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.