bridge

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2017 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package bridge implements the interface between Go and Objective-C. See https://gomatcha.io/guide/native-bridge/ for more details.

Index

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

func RegisterType(str string, t reflect.Type)

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 Array

func Array(a ...*Value) *Value

Array creates an NSArray containing a, and wraps it in a Value.

func Bool

func Bool(v bool) *Value

Bool creates an NSNumber containing v, and wraps it in a Value.

func Bridge

func Bridge(a string) *Value

Bridge gets the MatchaObjcBridge singleton, and wraps it in a Value.

func Bytes

func Bytes(v []byte) *Value

Bytes creates an NSData containing v, and wraps it in a Value.

func Float64

func Float64(v float64) *Value

Float64 creates an NSNumber containing v, and wraps it in a Value.

func Int64

func Int64(v int64) *Value

Int64 creates an NSNumber containing v, and wraps it in a Value.

func Interface

func Interface(v interface{}) *Value

Interface creates an MatchaGoValue containing v, and wraps it in a Value.

func Nil

func Nil() *Value

Nil returns the Value representing the ObjectiveC nil.

func String

func String(v string) *Value

String creates an NSString containing v, and wraps it in a Value.

func (*Value) Call

func (v *Value) Call(s string, args ...*Value) *Value

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) IsNil

func (v *Value) IsNil() bool

IsNil returns true if v wraps the ObjectievC nil.

func (*Value) ToArray

func (v *Value) ToArray() []*Value

ToString returns v's elements a slice of Value. v must wrap a NSArray.

func (*Value) ToBool

func (v *Value) ToBool() bool

ToBool returns v's value expressed as a boolean. v must wrap a NSNumber.

func (*Value) ToBytes

func (v *Value) ToBytes() []byte

ToString returns v's value as a byte slice. v must wrap a NSData.

func (*Value) ToFloat64

func (v *Value) ToFloat64() float64

ToFloat64 returns v's value expressed as a float64. v must wrap a NSNumber.

func (*Value) ToInt64

func (v *Value) ToInt64() int64

ToInt64 returns v's value expressed as an int64. 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.

func (*Value) ToString

func (v *Value) ToString() string

ToString returns v's value as a string. v must wrap a NSString.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL