x/mobile: ObjC: binding callback #25847
Labels
FrozenDueToAge
mobile
Android, iOS, and x/mobile
WaitingForInfo
Issue is not actionable because of missing required information, which needs to be provided.
Milestone
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
)?GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/fil/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/fil/go"
GORACE=""
GOROOT="/opt/local/lib/go"
GOTMPDIR=""
GOTOOLDIR="/opt/local/lib/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="/usr/bin/clang"
CXX="clang++"
CGO_ENABLED="1"
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/_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;
(instancetype)initWithRef:(id)ref;
(void)onResult:(NSString*)json;
@EnD
`
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'
The text was updated successfully, but these errors were encountered: