golang/go

x/mobile: Add support for callback blocks in ObjC reverse bindings with matching Go function signatures

Open

#35.967 aperta il 4 dic 2019

Vedi su GitHub
 (2 commenti) (0 reazioni) (0 assegnatari)Go (19.008 fork)batch import
FeatureRequestNeedsInvestigationhelp wantedmobile

Metriche repository

Star
 (133.883 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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

Does this issue reproduce with the latest release?

Yes

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

What did you do?

Attempted to use a function pointer as a block parameter in ObjC reverse bindings

What did you expect to see?

I hoped it would work

What did you see instead?

Compilation error: implicit type "void" not found

Assume the function:

import (
	"ObjC/UserNotifications"
	"ObjC/UserNotifications/UNUserNotificationCenter"
)

func testBinding() {
	unc := UNUserNotificationCenter.CurrentNotificationCenter()
	handler := func(settings *UserNotifications.UNNotificationSettings) {
		// TODO
	}
	unc.GetNotificationSettingsWithCompletionHandler(handler)
}

Getting reference to the UNUserNotificationCenter singleton compiles and works. However, simply referencing the GetNotificationSettingsWithCompletionHandler function causes a compiler error when trying to understand the method signature looking for a completion handler.

GOMOBILE=/Users/dave/go/pkg/gomobile
WORK=/var/folders/4j/j8tb1q2s4kd3rdn0v_hzh_6m0000gn/T/gomobile-work-846542795
GOOS=darwin CGO_ENABLED=1 /Users/dave/go/bin/gobind -lang=go,objc -outdir=$WORK -tags=ios poc/poc
rm -r -f "$WORK"
gomobile: /Users/dave/go/bin/gobind -lang=go,objc -outdir=/var/folders/4j/j8tb1q2s4kd3rdn0v_hzh_6m0000gn/T/gomobile-work-846542795 -tags=ios poc/poc failed: exit status 1
2019/12/04 13:30:59 implicit type "void" not found

Guida contributor