Documentation ¶
Overview ¶
Package bridge implements the interface between Go and Objective-C. See https://gomatcha.io/guide/native-bridge/ for more details.
Index ¶
- func RegisterFunc(str string, f interface{})
- func RegisterType(str string, t reflect.Type)
- type Value
- func (v *Value) Call(s string, args ...*Value) *Value
- func (v *Value) IsNil() bool
- func (v *Value) ToArray() []*Value
- func (v *Value) ToBool() bool
- func (v *Value) ToBytes() []byte
- func (v *Value) ToFloat64() float64
- func (v *Value) ToInt64() int64
- func (v *Value) ToInterface() interface{}
- func (v *Value) ToString() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterFunc ¶
func RegisterFunc(str string, f interface{})
RegisterFunc registers a function that can be called from ObjC.
Go:
func init() { bridge.RegisterFunc("gomatcha.io/matcha/examples/simple Add", func(a, b int) int { return a + b }) }
Objective-C:
MatchaGoValue *func = [[MatchaGoValue alloc] initWithFunc:@"gomatcha.io/matcha/examples/simple Add"]; MatchaGoValue *a = [[MatchaGoValue alloc] initWithInt:1]; MatchaGoValue *b = [[MatchaGoValue alloc] initWithInt:3]; MatchaGoValue *c = [func call:nil args:@[a, b]]; NSLog(@"1+3=%@", @(c.toLongLong));
func RegisterType ¶
RegisterType registers a go type that can be created from Objc.
Go:
type struct Point { X float64 Y float64 } func (p Point) Print { fmt.Printf("{%v, %v}", p.X, p.Y) } func init() { bridge.RegisterType("gomatcha.io/matcha/layout.Point", reflect.TypeOf(Point{})) }
Objective-C:
MatchaGoValue *a = [[MatchaGoValue alloc] initWithType:@"gomatcha.io/matcha/layout.Point"]; a[@"X"] = [[MatchaGoValue alloc] initWithDouble:x]; a[@"Y"] = [[MatchaGoValue alloc] initWithDouble:y]; [a call:@"Print" args:nil];
Types ¶
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value wraps an ObjectiveC object.
func Interface ¶
func Interface(v interface{}) *Value
Interface creates an MatchaGoValue containing v, and wraps it in a Value.
func (*Value) Call ¶
Call calls a method on v with signature s and arguments args.
Go:
rlt := bridge.Bridge().Call("add::", bridge.Int64(1), bridge.Int64(3)) fmt.Printf("1+3=%v", rlt.ToInt64())
Objective-C:
@implementation MatchaObjcBridge (Extensions) - (void)add:(NSNumber *)a :(NSNumber *)b { return @(a.IntegerValue + b.IntegerValue) } @end
func (*Value) ToFloat64 ¶
ToFloat64 returns v's value expressed as a float64. v must wrap a NSNumber.
func (*Value) ToInterface ¶
func (v *Value) ToInterface() interface{}
ToInterface return's v's value as an interface{}, v must wrap a MatchaGoValue.
Click to show internal directories.
Click to hide internal directories.