objc

package
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package objc wrap objective-c runtime

Index

Constants

View Source
const (
	PropertyAttributeNameNonatomic = "N"
	PropertyAttributeNameStrong    = "&"
	PropertyAttributeNameRetain    = PropertyAttributeNameStrong
	PropertyAttributeNameWeak      = "W"
	PropertyAttributeNameReadonly  = "R"
	PropertyAttributeNameGetter    = "G"
	PropertyAttributeNameSetter    = "S"
	PropertyAttributeNameIvar      = "V"
	PropertyAttributeNameType      = "T"
)
View Source
const (
	ASSOCIATION_ASSIGN           = 0     // Specifies a weak reference to the associated object.
	ASSOCIATION_RETAIN_NONATOMIC = 1     // Specifies a strong reference to the associated object. The association is not made atomically.
	ASSOCIATION_COPY_NONATOMIC   = 3     // Specifies that the associated object is copied. The association is not made atomically.
	ASSOCIATION_RETAIN           = 01401 // Specifies a strong reference to the associated object. The association is made atomically.
	ASSOCIATION_COPY             = 01403 //Specifies that the associated object is copied. The association is made atomically.
)

Variables

This section is empty.

Functions

func AddClassMethod added in v0.17.0

func AddClassMethod(class Class, sel Selector, f any) bool

AddClassMethod add a new objc class method with a go function. The first param of go function should be the class, other params are mapped from objc method params.

func AddMethod added in v0.17.0

func AddMethod(class Class, sel Selector, f any) bool

AddMethod add a new objc instance method with a go function. The first param of go function should be the object instance, other params are mapped from objc method params.

func CallBlock added in v0.17.0

func CallBlock[T any](b Block, params ...any) T

func CallMethod added in v0.16.1

func CallMethod[T any](o Holder, selector Selector, params ...any) T

type T: the ret value type

func DisposeClassPair added in v0.17.2

func DisposeClassPair(class Class)

func ExtractPtr

func ExtractPtr(o Holder) unsafe.Pointer

ExtractPtr return the objc ptr hold by Object. If is nil, or contains a nil pointer, return nil

func MsgSend added in v0.17.0

func MsgSend[T any](receiver Holder, selector Selector, params ...any) T

MsgSend wraps objc_msgSend type param T: the return value type. using Void for non-return value method.

func MsgSendStret added in v0.17.0

func MsgSendStret[T any](receiver Holder, selector Selector, params ...any) T

objc_msgSend_stret Note: arm64 do not need to use this for method that return a struct type.

func MsgSendSuper added in v0.17.0

func MsgSendSuper[T any](receiver Holder, selector Selector, params ...any) T

objc_msgSendSuper

func MsgSendSuperStret added in v0.17.0

func MsgSendSuperStret[T any](receiver Holder, selector Selector, params ...any) T

objc_msgSendSuper_stret Note: arm64 do not need to use this for method that return a struct type.

func RegisterClassPair added in v0.13.1

func RegisterClassPair(class Class)

func RemoveAssociatedObjects added in v0.13.5

func RemoveAssociatedObjects(o IObject)

func ReplaceClassMethod added in v0.17.0

func ReplaceClassMethod(class Class, sel Selector, f any)

ReplaceClassMethod replace objc class method with a go function. The first param of go function should be the class, other params are mapped from objc method params.

func ReplaceMethod added in v0.17.0

func ReplaceMethod(class Class, sel Selector, f any)

ReplaceMethod replace objc instance method with a go function. The first param of go function should be the object instance, other params are mapped from objc method params.

func SetAssociatedObject added in v0.13.5

func SetAssociatedObject(o IObject, key unsafe.Pointer, value IObject, policy AssociationPolicy)

func SetDeallocListener added in v0.14.0

func SetDeallocListener(o IObject, listener func())

SetDeallocListener set a listener to be invoked when object ref count is decreased to zero(so the object is dealloced). Call dealloc method directly, but ref count is still large than 0 will not trigger the listener. Call multi times will remove previouse listener.

func SetRetainAssociated added in v0.18.1

func SetRetainAssociated(o IObject, key string, delegate IObject)

func SetRetainDelegateAssociated added in v0.18.0

func SetRetainDelegateAssociated(o IObject, delegate IObject)

func ToGoBytes added in v0.16.1

func ToGoBytes(p unsafe.Pointer) []byte

func ToGoMap added in v0.16.1

func ToGoMap(ptr unsafe.Pointer, mapType reflect.Type) reflect.Value

func ToGoSlice added in v0.16.1

func ToGoSlice(ptr unsafe.Pointer, sliceType reflect.Type) reflect.Value

func ToGoString added in v0.16.1

func ToGoString(p unsafe.Pointer) string

func ToNSArray added in v0.16.1

func ToNSArray(slice reflect.Value) unsafe.Pointer

func ToNSData added in v0.16.1

func ToNSData(bytes []byte) unsafe.Pointer

func ToNSDict added in v0.16.1

func ToNSDict(m reflect.Value) unsafe.Pointer

func ToNSString added in v0.16.1

func ToNSString(s string) unsafe.Pointer

func WithAutoreleasePool

func WithAutoreleasePool(task func())

WithAutoreleasePool run code in a new auto release pool.

Types

type AssociationPolicy added in v0.13.5

type AssociationPolicy uintptr

type Block added in v0.13.2

type Block struct {
	// contains filtered or unexported fields
}

func CreateGlobalBlock added in v0.17.0

func CreateGlobalBlock(f any) Block

func CreateMallocBlock added in v0.17.0

func CreateMallocBlock(f any) Block

CreateMallocBlock wrap a go function to objc block. f is the go function to wrap as a objc block

func MakeBlock added in v0.13.2

func MakeBlock(ptr unsafe.Pointer) Block

func (Block) Copy added in v0.13.2

func (b Block) Copy() Block

func (Block) Ptr added in v0.13.2

func (b Block) Ptr() unsafe.Pointer

func (Block) Release added in v0.13.2

func (b Block) Release()

type Category added in v0.8.3

type Category struct {
	// contains filtered or unexported fields
}

func (Category) Ptr added in v0.9.4

func (c Category) Ptr() unsafe.Pointer

type Class added in v0.8.3

type Class struct {
	// contains filtered or unexported fields
}

Class is objc Class

func AllocateClassPair added in v0.13.1

func AllocateClassPair(superClass Class, name string, extraBytes uint) Class

func GetClass added in v0.8.3

func GetClass(name string) Class

GetClass get and return an objc Class by name

func (Class) AddMethod added in v0.13.1

func (c Class) AddMethod(sel Selector, imp IMP, types string) bool

func (Class) AddProperty added in v0.14.1

func (c Class) AddProperty(name string, attributes []PropertyAttribute) bool

func (Class) AddProtocol added in v0.13.1

func (c Class) AddProtocol(protocol Protocol) bool

func (Class) CopyMethodList added in v0.13.2

func (c Class) CopyMethodList() []Method

func (Class) CopyPropertyList added in v0.14.1

func (c Class) CopyPropertyList() []Property

func (Class) CreateInstance added in v0.8.3

func (c Class) CreateInstance(idxIvars uint) Object

func (Class) GetClass added in v0.17.0

func (c Class) GetClass() Class

GetClass returns class's meta class.

func (Class) GetClassMethod added in v0.13.1

func (c Class) GetClassMethod(sel Selector) Method

func (Class) GetInstanceMethod added in v0.13.1

func (c Class) GetInstanceMethod(sel Selector) Method

func (Class) GetMethodImplementation added in v0.13.1

func (c Class) GetMethodImplementation(sel Selector) IMP

func (Class) GetMethodImplementationStret added in v0.13.1

func (c Class) GetMethodImplementationStret(sel Selector) IMP

func (Class) GetName added in v0.8.3

func (c Class) GetName() string

func (Class) GetProperty added in v0.14.1

func (c Class) GetProperty(name string) Property

func (Class) GetSuperClass added in v0.8.3

func (c Class) GetSuperClass() Class

func (Class) GetVersion added in v0.8.3

func (c Class) GetVersion() int

func (Class) Ptr added in v0.9.4

func (c Class) Ptr() unsafe.Pointer

func (Class) ReplaceMethod added in v0.13.1

func (c Class) ReplaceMethod(sel Selector, imp IMP, types string) IMP

func (Class) ReplaceProperty added in v0.14.1

func (c Class) ReplaceProperty(name string, attributes []PropertyAttribute)

func (Class) RespondsToSelector added in v0.13.1

func (c Class) RespondsToSelector(sel Selector) bool

func (Class) SetVersion added in v0.8.3

func (c Class) SetVersion(version int)

type Holder added in v0.10.7

type Holder interface {
	// Ptr return the delegate objc pointer
	Ptr() unsafe.Pointer
}

Holder is an interface for holding an objc pointer

type IClass added in v0.13.6

type IClass interface {
	Holder
	CreateInstance(idxIvars uint) Object
	GetName() string
	SetVersion(version int)
	GetVersion()
	GetSuperClass() Class
	RespondsToSelector(sel Selector) bool
	AddMethod(sel Selector, imp IMP, types string) bool
	ReplaceMethod(sel Selector, imp IMP, types string) IMP
	GetMethodImplementation(sel Selector) IMP
	GetMethodImplementationStret(sel Selector)
	GetInstanceMethod(sel Selector) Method
	GetClassMethod(sel Selector) Method
	CopyMethodList() []Method
}

make generated code happy

type IMP

type IMP struct {
	// contains filtered or unexported fields
}

IMP is function pointer

func IMPWithBlock added in v0.14.5

func IMPWithBlock(b Block) IMP

func MakeIMP added in v0.13.1

func MakeIMP(ptr unsafe.Pointer) IMP

func (IMP) GetBlock added in v0.14.5

func (i IMP) GetBlock() Block

func (IMP) Ptr added in v0.13.1

func (i IMP) Ptr() unsafe.Pointer

func (IMP) RemoveBlock added in v0.14.5

func (i IMP) RemoveBlock() bool

type IObject added in v0.11.0

type IObject interface {
	Holder
	IsNil() bool

	GetClass() Class
	IsKindOfClass(class Class) bool
	IsMemberOfClass(class Class) bool
	RespondsToSelector(sel Selector) bool
	ConformsToProtocol(protocol Protocol) bool

	Bind(binding string, toObject IObject, keyPath string, options map[string]IObject)

	IsProxy() bool

	Retain() Object
	Release()
	Autorelease() Object
	RetainCount() uint

	Dealloc()
	Description() string
}

IObject is interface for all objc Object type

type Integer added in v0.14.1

type Integer = int64

type Ivar added in v0.8.3

type Ivar struct {
	// contains filtered or unexported fields
}

func (Ivar) Ptr added in v0.9.4

func (i Ivar) Ptr() unsafe.Pointer

type Method added in v0.8.3

type Method struct {
	// contains filtered or unexported fields
}

func (Method) GetImplementation added in v0.13.1

func (m Method) GetImplementation() IMP

func (Method) GetName added in v0.13.1

func (m Method) GetName() Selector

func (Method) GetTypeEncoding added in v0.13.1

func (m Method) GetTypeEncoding() string

func (Method) Ptr added in v0.9.4

func (m Method) Ptr() unsafe.Pointer

func (Method) SetImplementation added in v0.13.1

func (m Method) SetImplementation(imp IMP) IMP

type MethodDescription added in v0.13.1

type MethodDescription struct {
	Name  Selector
	Types string
}

type Object

type Object struct {
	// contains filtered or unexported fields
}

Object is wrapper for objc-NSObject

func GetAssociatedObject added in v0.13.5

func GetAssociatedObject(o IObject, key unsafe.Pointer) Object

func MakeObject

func MakeObject(ptr unsafe.Pointer) Object

func NewObject

func NewObject() Object

func WrapAsProtocol added in v0.17.2

func WrapAsProtocol[T any](protocolName string, d T) Object

WrapAsProtocol wrap go interface to protocol implement instance.

param protocolName: the delegate go interface name param d: the delegate go implementaion

func (Object) Autorelease added in v0.11.0

func (o Object) Autorelease() Object

func (Object) Bind added in v0.19.0

func (o Object) Bind(binding string, toObject IObject, keyPath string, options map[string]IObject)

func (Object) ConformsToProtocol added in v0.9.1

func (o Object) ConformsToProtocol(protocol Protocol) bool

func (Object) Dealloc

func (o Object) Dealloc()

func (Object) Description

func (o Object) Description() string

func (Object) GetClass added in v0.8.3

func (o Object) GetClass() Class

func (Object) IsKindOfClass added in v0.9.1

func (o Object) IsKindOfClass(class Class) bool

func (Object) IsMemberOfClass added in v0.9.1

func (o Object) IsMemberOfClass(class Class) bool

func (Object) IsNil added in v0.13.5

func (o Object) IsNil() bool

func (Object) IsProxy added in v0.9.1

func (o Object) IsProxy() bool

func (Object) PerformSelector added in v0.11.0

func (o Object) PerformSelector(sel Selector) Object

func (Object) PerformSelector_WithObject added in v0.11.0

func (o Object) PerformSelector_WithObject(sel Selector, object Object) Object

func (Object) PerformSelector_WithObject_WithObject added in v0.11.0

func (o Object) PerformSelector_WithObject_WithObject(sel Selector, obj1, obj2 Object) Object

func (Object) Ptr added in v0.11.0

func (o Object) Ptr() unsafe.Pointer

func (Object) Release

func (o Object) Release()

func (Object) RespondsToSelector added in v0.9.1

func (o Object) RespondsToSelector(sel Selector) bool

func (Object) Retain added in v0.11.0

func (o Object) Retain() Object

func (Object) RetainCount added in v0.9.1

func (o Object) RetainCount() uint

type Property added in v0.13.1

type Property struct {
	// contains filtered or unexported fields
}

func (Property) CopyAttributeList added in v0.14.1

func (p Property) CopyAttributeList() []PropertyAttribute

func (Property) CopyAttributeValue added in v0.14.1

func (p Property) CopyAttributeValue(name string) string

func (Property) GetAttributes added in v0.14.1

func (p Property) GetAttributes() string

func (Property) GetName added in v0.14.1

func (p Property) GetName() string

func (Property) Ptr added in v0.13.1

func (p Property) Ptr() unsafe.Pointer

type PropertyAttribute added in v0.14.1

type PropertyAttribute struct {
	Name  string
	Value string
}

type Protocol added in v0.8.3

type Protocol struct {
	// contains filtered or unexported fields
}

func AllocateProtocol added in v0.13.1

func AllocateProtocol(name string) Protocol

func GetProtocol added in v0.13.1

func GetProtocol(name string) Protocol

func (Protocol) CopyMethodDescriptionList added in v0.13.1

func (p Protocol) CopyMethodDescriptionList(required bool, instanceMethod bool) []MethodDescription

func (Protocol) CopyPropertyList added in v0.14.1

func (p Protocol) CopyPropertyList() []Property

func (Protocol) CopyProtocolList added in v0.13.1

func (p Protocol) CopyProtocolList() []Protocol

func (Protocol) GetMethodDescription added in v0.13.1

func (p Protocol) GetMethodDescription(sel Selector, required bool, instanceMethod bool) MethodDescription

func (Protocol) GetName added in v0.13.1

func (p Protocol) GetName() string

func (Protocol) GetProperty added in v0.14.1

func (p Protocol) GetProperty(name string, required bool, isInstanceProperty bool) Property

func (Protocol) Ptr added in v0.9.4

func (p Protocol) Ptr() unsafe.Pointer

type ProtocolBase added in v0.19.1

type ProtocolBase struct {
	Object
}

ProtocolBase is parent protocol for Protocol Creator, that can carry extra datas.

func (ProtocolBase) Extra added in v0.19.1

func (p ProtocolBase) Extra() any

Extra gets and returns extra data associate with the protocol object. If not extra data is set, return nil.

func (ProtocolBase) SetExtra added in v0.19.1

func (p ProtocolBase) SetExtra(data any)

SetExtra set extra data associate with the protocol object.

type Selector

type Selector struct {
	// contains filtered or unexported fields
}

Selector for select and hold method

func MakeSelector added in v0.8.3

func MakeSelector(ptr unsafe.Pointer) Selector

func SEL added in v0.19.1

func SEL(selName string) Selector

SEL return a method selector by the name. The selector is cached at go side.

func SelectorRegisterName added in v0.8.3

func SelectorRegisterName(name string) Selector

SelectorRegisterName registers a method with the Objective-C runtime system, maps the method name to a selector, and returns the selector value

func (Selector) GetName added in v0.8.3

func (s Selector) GetName() string

GetName return selector name

func (Selector) Ptr added in v0.8.3

func (s Selector) Ptr() unsafe.Pointer

type UInteger added in v0.14.1

type UInteger = uint64

type Void added in v0.16.1

type Void struct{}

for void type

Jump to

Keyboard shortcuts

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