Documentation
¶
Overview ¶
Package objc wrap objective-c runtime
Index ¶
- Constants
- func AddClassMethod(class Class, sel Selector, f any) bool
- func AddMethod(class Class, sel Selector, f any) bool
- func CallBlock[T any](b Block, params ...any) T
- func CallMethod[T any](o Holder, selector Selector, params ...any) T
- func DisposeClassPair(class Class)
- func ExtractPtr(o Holder) unsafe.Pointer
- func MsgSend[T any](receiver Holder, selector Selector, params ...any) T
- func MsgSendStret[T any](receiver Holder, selector Selector, params ...any) T
- func MsgSendSuper[T any](receiver Holder, selector Selector, params ...any) T
- func MsgSendSuperStret[T any](receiver Holder, selector Selector, params ...any) T
- func RegisterClassPair(class Class)
- func RemoveAssociatedObjects(o IObject)
- func ReplaceClassMethod(class Class, sel Selector, f any)
- func ReplaceMethod(class Class, sel Selector, f any)
- func SetAssociatedObject(o IObject, key unsafe.Pointer, value IObject, policy AssociationPolicy)
- func SetDeallocListener(o IObject, listener func())
- func SetRetainAssociated(o IObject, key string, delegate IObject)
- func SetRetainDelegateAssociated(o IObject, delegate IObject)
- func ToGoBytes(p unsafe.Pointer) []byte
- func ToGoMap(ptr unsafe.Pointer, mapType reflect.Type) reflect.Value
- func ToGoSlice(ptr unsafe.Pointer, sliceType reflect.Type) reflect.Value
- func ToGoString(p unsafe.Pointer) string
- func ToNSArray(slice reflect.Value) unsafe.Pointer
- func ToNSData(bytes []byte) unsafe.Pointer
- func ToNSDict(m reflect.Value) unsafe.Pointer
- func ToNSString(s string) unsafe.Pointer
- func WithAutoreleasePool(task func())
- type AssociationPolicy
- type Block
- type Category
- type Class
- func (c Class) AddMethod(sel Selector, imp IMP, types string) bool
- func (c Class) AddProperty(name string, attributes []PropertyAttribute) bool
- func (c Class) AddProtocol(protocol Protocol) bool
- func (c Class) CopyMethodList() []Method
- func (c Class) CopyPropertyList() []Property
- func (c Class) CreateInstance(idxIvars uint) Object
- func (c Class) GetClass() Class
- func (c Class) GetClassMethod(sel Selector) Method
- func (c Class) GetInstanceMethod(sel Selector) Method
- func (c Class) GetMethodImplementation(sel Selector) IMP
- func (c Class) GetMethodImplementationStret(sel Selector) IMP
- func (c Class) GetName() string
- func (c Class) GetProperty(name string) Property
- func (c Class) GetSuperClass() Class
- func (c Class) GetVersion() int
- func (c Class) Ptr() unsafe.Pointer
- func (c Class) ReplaceMethod(sel Selector, imp IMP, types string) IMP
- func (c Class) ReplaceProperty(name string, attributes []PropertyAttribute)
- func (c Class) RespondsToSelector(sel Selector) bool
- func (c Class) SetVersion(version int)
- type Holder
- type IClass
- type IMP
- type IObject
- type Integer
- type Ivar
- type Method
- type MethodDescription
- type Object
- func (o Object) Autorelease() Object
- func (o Object) Bind(binding string, toObject IObject, keyPath string, options map[string]IObject)
- func (o Object) ConformsToProtocol(protocol Protocol) bool
- func (o Object) Dealloc()
- func (o Object) Description() string
- func (o Object) GetClass() Class
- func (o Object) IsKindOfClass(class Class) bool
- func (o Object) IsMemberOfClass(class Class) bool
- func (o Object) IsNil() bool
- func (o Object) IsProxy() bool
- func (o Object) PerformSelector(sel Selector) Object
- func (o Object) PerformSelector_WithObject(sel Selector, object Object) Object
- func (o Object) PerformSelector_WithObject_WithObject(sel Selector, obj1, obj2 Object) Object
- func (o Object) Ptr() unsafe.Pointer
- func (o Object) Release()
- func (o Object) RespondsToSelector(sel Selector) bool
- func (o Object) Retain() Object
- func (o Object) RetainCount() uint
- type Property
- type PropertyAttribute
- type Protocol
- func (p Protocol) CopyMethodDescriptionList(required bool, instanceMethod bool) []MethodDescription
- func (p Protocol) CopyPropertyList() []Property
- func (p Protocol) CopyProtocolList() []Protocol
- func (p Protocol) GetMethodDescription(sel Selector, required bool, instanceMethod bool) MethodDescription
- func (p Protocol) GetName() string
- func (p Protocol) GetProperty(name string, required bool, isInstanceProperty bool) Property
- func (p Protocol) Ptr() unsafe.Pointer
- type ProtocolBase
- type Selector
- type UInteger
- type Void
Constants ¶
const ( PropertyAttributeNameNonatomic = "N" PropertyAttributeNameStrong = "&" PropertyAttributeNameRetain = PropertyAttributeNameStrong PropertyAttributeNameWeak = "W" PropertyAttributeNameReadonly = "R" PropertyAttributeNameGetter = "G" PropertyAttributeNameSetter = "S" PropertyAttributeNameIvar = "V" PropertyAttributeNameType = "T" )
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
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
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 CallMethod ¶ added in v0.16.1
type T: the ret value type
func DisposeClassPair ¶ added in v0.17.2
func DisposeClassPair(class Class)
func ExtractPtr ¶
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
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
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
objc_msgSendSuper
func MsgSendSuperStret ¶ added in v0.17.0
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
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
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 SetRetainDelegateAssociated ¶ added in v0.18.0
func ToGoString ¶ added in v0.16.1
func ToNSString ¶ added in v0.16.1
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 CreateMallocBlock ¶ added in v0.17.0
CreateMallocBlock wrap a go function to objc block. f is the go function to wrap as a objc block
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 (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 (Class) CopyMethodList ¶ added in v0.13.2
func (Class) CopyPropertyList ¶ added in v0.14.1
func (Class) CreateInstance ¶ added in v0.8.3
func (Class) GetClassMethod ¶ added in v0.13.1
func (Class) GetInstanceMethod ¶ added in v0.13.1
func (Class) GetMethodImplementation ¶ added in v0.13.1
func (Class) GetMethodImplementationStret ¶ added in v0.13.1
func (Class) GetProperty ¶ added in v0.14.1
func (Class) GetSuperClass ¶ added in v0.8.3
func (Class) GetVersion ¶ added in v0.8.3
func (Class) ReplaceMethod ¶ added in v0.13.1
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 (Class) SetVersion ¶ added in v0.8.3
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 (IMP) RemoveBlock ¶ added in v0.14.5
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 Method ¶ added in v0.8.3
type Method struct {
// contains filtered or unexported fields
}
func (Method) GetImplementation ¶ added in v0.13.1
func (Method) GetTypeEncoding ¶ added in v0.13.1
func (Method) SetImplementation ¶ added in v0.13.1
type MethodDescription ¶ added in v0.13.1
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
Object is wrapper for objc-NSObject
func GetAssociatedObject ¶ added in v0.13.5
func MakeObject ¶
func WrapAsProtocol ¶ added in v0.17.2
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 (Object) ConformsToProtocol ¶ added in v0.9.1
func (Object) Description ¶
func (Object) IsKindOfClass ¶ added in v0.9.1
func (Object) IsMemberOfClass ¶ added in v0.9.1
func (Object) PerformSelector ¶ added in v0.11.0
func (Object) PerformSelector_WithObject ¶ added in v0.11.0
func (Object) PerformSelector_WithObject_WithObject ¶ added in v0.11.0
func (Object) RespondsToSelector ¶ added in v0.9.1
func (Object) RetainCount ¶ added in v0.9.1
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 (Property) GetAttributes ¶ added in v0.14.1
type PropertyAttribute ¶ added in v0.14.1
type Protocol ¶ added in v0.8.3
type Protocol struct {
// contains filtered or unexported fields
}
func AllocateProtocol ¶ added in v0.13.1
func GetProtocol ¶ added in v0.13.1
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 (Protocol) CopyProtocolList ¶ added in v0.13.1
func (Protocol) GetMethodDescription ¶ added in v0.13.1
func (p Protocol) GetMethodDescription(sel Selector, required bool, instanceMethod bool) MethodDescription
func (Protocol) GetProperty ¶ added in v0.14.1
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 SEL ¶ added in v0.19.1
SEL return a method selector by the name. The selector is cached at go side.
func SelectorRegisterName ¶ added in v0.8.3
SelectorRegisterName registers a method with the Objective-C runtime system, maps the method name to a selector, and returns the selector value