objc

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2023 License: MIT, BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package objc implements access to the Objective-C runtime from Go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Autorelease added in v0.2.0

func Autorelease(body func())

func RefPointer added in v0.2.0

func RefPointer(o Ref) unsafe.Pointer

func RegisterClass

func RegisterClass(class Class)

RegisterClass registers a Class with the Objective-C runtime.

func RegisterSelector

func RegisterSelector(name string) unsafe.Pointer

Types

type Class

type Class interface {
	Object

	// AddMethod registers a Go function to be called whenever
	// an instance of the class receives a message for the given
	// selector.
	//
	// The AddMethod call only works for classes created with
	// objc.NewClass. Method calls will only be received by the
	// Go function if instances of the class are instanciated
	// by calling objc.NewGoInstance.
	AddMethod(selector string, fn interface{})

	// Swizzle swaps the implementation of two methods on a class
	// so that messages sent to selectorA are received by the
	// implementation of selectorB and vice-versa.
	Swizzle(selectorA, selectorB string)
}

A Class represents a special Objective-C class Object.

func Get

func Get(name string) Class

Get looks up a class by name.

func GetClass

func GetClass(name string) Class

deprecated

func NewClass

func NewClass(classname string, superclass string) Class

func NewClassFromStruct

func NewClassFromStruct(value interface{}) Class

NewClass returns a new class. The value parameter must point to a value of the struct that is used to represent instances of the class in Go.

type Object

type Object interface {
	Ref

	// SendMsg sends an arbitrary message to the method on the
	// object that is identified by selectorName.
	Send(selector string, args ...interface{}) Object

	// SendSuperMsg is like SendMsg, but sends to the object's
	// super class instead.
	SendSuper(selector string, args ...interface{}) Object

	// Class returns the the special class object corresponding
	// to this object.
	Class() Class

	// Alloc sends the  "alloc" message to the object.
	Alloc() Object

	// Init sends the "init" message to the object.
	Init() Object

	// Retain sends the "retain" message to the object.
	Retain() Object

	// Release sends the "release" message to the object.
	Release() Object

	// Autorelease sends the "autorelease" message to the object.
	Autorelease() Object

	// Copy sends the "copy" message to the object.
	Copy() Object

	Equals(o Object) bool

	// String returns a string-representation of the object.
	// This is equivalent to sending the "description"
	// message to the object, except that this method
	// returns a Go string.
	String() string

	// Uint returns the value of the object as an uint64.
	Uint() uint64

	// Int returns the value of the object as an int64.
	Int() int64

	// Float returns the value of the object as a float64.
	Float() float64

	// Bool returns the value of the object as a bool.
	Bool() bool

	// CString returns the value of the object as a C string.
	CString() string

	Set(setter string, args ...interface{})
	Get(getter string) Object
	GetSt(getter string, ret interface{})
}

An Object represents an Objective-C object, along with some convenience methods only found on NSObjects.

func ObjectPtr

func ObjectPtr(ptr uintptr) Object

func Object_fromPointer added in v0.2.0

func Object_fromPointer(id unsafe.Pointer) Object

func Object_fromRef added in v0.2.0

func Object_fromRef(ref Ref) Object

type Ref added in v0.2.0

type Ref interface {
	// Pointer returns the in-memory address of the object.
	Pointer() uintptr
}

A Ref represents an Objective-C object. The basic interface only includes the address (aka ID) of the object. For richer wrapper, use `Object`.

type Selector

type Selector interface {
	// Selector returns a string representation of
	// a selector.
	Selector() string

	// String returns the same string as Selector does.
	// It is only implemented to implement the Stringer
	// interface.
	String() string

	// Objective-C address for the selector.
	// NOTE: this could have used `Ref` for the address interface, though using a
	// different method for the interface keeps them distinct from objects.
	SelectorAddress() unsafe.Pointer
}

A Selector represents an Objective-C method selector.

func GetSelector

func GetSelector(name string) Selector

deprecated

func Sel

func Sel(name string) Selector

GetSelector looks up a Selector by name.

func SelectorAt added in v0.2.0

func SelectorAt(p unsafe.Pointer) Selector

Jump to

Keyboard shortcuts

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