Documentation ¶
Overview ¶
Gain low-level access to the Objective-C runtime and the Objective-C root types.
If it's not documented it's not meant to be used directly, but you can find the equivalent type or function in the Apple documentation.
Index ¶
- Constants
- func AddClassMethod(class IClass, sel Selector, f any) bool
- func AddMethod(class IClass, sel Selector, f any) bool
- func AssociationKey(name string) unsafe.Pointer
- func Call[T any](o Handle, selector Selector, params ...any) T
- func CallBlock[T any](b Block, params ...any) T
- func DisposeClass(class IClass)
- func ForceCast[S any, T any](v S) T
- func Ptr(o Handle) unsafe.Pointer
- func RegisterClass(class IClass)
- func RemoveAssociatedObjects(o IObject)
- func ReplaceClassMethod(class IClass, sel Selector, f any)
- func ReplaceMethod(class IClass, sel Selector, f any)
- func Retain(o IObject)
- func SetAssociatedObject(o IObject, key unsafe.Pointer, value IObject, policy AssociationPolicy)
- func SetDeallocListener(o Object, listener func())
- 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) ClassMethod(sel Selector) Method
- func (c Class) CopyMethodList() []Method
- func (c Class) CopyPropertyList() []Property
- func (c Class) CreateInstance(idxIvars uint) Object
- func (c Class) InstanceMethod(sel Selector) Method
- func (c Class) MetaClass() Class
- func (c Class) MethodImplementation(sel Selector) IMP
- func (c Class) MethodImplementationStret(sel Selector) IMP
- func (c Class) Name() string
- func (c Class) Property(name string) Property
- 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)
- func (c Class) SuperClass() Class
- func (c Class) Version() int
- type Handle
- type IClass
- type IMP
- type IObject
- type IProtocol
- type Integer
- type Ivar
- type Method
- type MethodDescription
- type Object
- func (o Object) Autorelease() Object
- func (o Object) Class() Class
- func (o Object) ConformsToProtocol(protocol Protocol) bool
- func (o Object) Dealloc()
- func (o Object) Description() string
- 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) PerformSelectorWithObject(sel Selector, object Object) Object
- func (o Object) PerformSelectorWithObjectWithObject(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) MethodDescription(sel Selector, required bool, instanceMethod bool) MethodDescription
- func (p Protocol) Name() string
- func (p Protocol) Property(name string, required bool, isInstanceProperty bool) Property
- func (p Protocol) Ptr() unsafe.Pointer
- type Selector
- type SyncCache
- type UInteger
- type UserClass
- 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 ¶
AddClassMethod adds a class method using a Go function. The first argument of the Go function should be the class, the second argument should be the method selector.
func AddMethod ¶
AddMethod adds an instance method using a Go function. The first argument of the Go function should be the object instance, the second argument should be the method selector.
func AssociationKey ¶
AssociationKey return key for AssociatedObject
func DisposeClass ¶
func DisposeClass(class IClass)
Destroys a class and its associated metaclass. Full Topic
func RegisterClass ¶
func RegisterClass(class IClass)
Registers a class that was allocated using AllocateClass Full Topic
func RemoveAssociatedObjects ¶
func RemoveAssociatedObjects(o IObject)
Removes all associations for a given object. Full Topic
func ReplaceClassMethod ¶
ReplaceClassMethod replaces a class method using a Go function. The first argument of the Go function should be the class, the second argument should be the method selector.
func ReplaceMethod ¶
ReplaceMethod replaces an instance method using a Go function. The first argument of the Go function should be the object instance, the second argument should be the method selector.
func Retain ¶
func Retain(o IObject)
Retain will retain the object and set a finalizer for the Go GC to release. This is the preferred way to retain objects. Note the object must be passed by reference.
func SetAssociatedObject ¶
func SetAssociatedObject(o IObject, key unsafe.Pointer, value IObject, policy AssociationPolicy)
Sets an associated value for a given object using a given key and association policy. Full Topic
func SetDeallocListener ¶
func SetDeallocListener(o Object, 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 ToGoString ¶
func ToNSString ¶
func WithAutoreleasePool ¶
func WithAutoreleasePool(task func())
WithAutoreleasePool runs code in a new AutoreleasePool.
Types ¶
type AssociationPolicy ¶
type AssociationPolicy uintptr
Type to specify the behavior of an association. Full Topic
type Block ¶
type Block struct {
// contains filtered or unexported fields
}
func CreateGlobalBlock ¶
CreateMallocBlock wraps a Go function as a global Block.
func CreateMallocBlock ¶
CreateMallocBlock wraps a Go function as an autoreleased Block.
type Class ¶
type Class struct {
// contains filtered or unexported fields
}
func AllocateClass ¶
Creates a new class and metaclass. Full Topic
func (Class) AddProperty ¶
func (c Class) AddProperty(name string, attributes []PropertyAttribute) bool
func (Class) AddProtocol ¶
func (Class) ClassMethod ¶
func (Class) CopyMethodList ¶
func (Class) CopyPropertyList ¶
func (Class) CreateInstance ¶
func (Class) InstanceMethod ¶
func (Class) MethodImplementation ¶
func (Class) MethodImplementationStret ¶
func (Class) ReplaceProperty ¶
func (c Class) ReplaceProperty(name string, attributes []PropertyAttribute)
func (Class) RespondsToSelector ¶
func (Class) SetVersion ¶
func (Class) SuperClass ¶
type IClass ¶
type IClass interface { Handle CreateInstance(idxIvars uint) Object Name() string SetVersion(version int) Version() int MetaClass() Class SuperClass() Class RespondsToSelector(sel Selector) bool AddMethod(sel Selector, imp IMP, types string) bool ReplaceMethod(sel Selector, imp IMP, types string) IMP MethodImplementation(sel Selector) IMP MethodImplementationStret(sel Selector) IMP InstanceMethod(sel Selector) Method ClassMethod(sel Selector) Method Property(name string) Property AddProperty(name string, attributes []PropertyAttribute) bool ReplaceProperty(name string, attributes []PropertyAttribute) AddProtocol(protocol Protocol) bool CopyMethodList() []Method CopyPropertyList() []Property }
type IMP ¶
type IMP struct {
// contains filtered or unexported fields
}
func IMPWithBlock ¶
func (IMP) RemoveBlock ¶
type IObject ¶
type IObject interface { Handle IsNil() bool Class() Class IsKindOfClass(class Class) bool IsMemberOfClass(class Class) bool RespondsToSelector(sel Selector) bool ConformsToProtocol(protocol Protocol) bool IsProxy() bool Retain() Object Release() Autorelease() Object RetainCount() uint Dealloc() Description() string }
An interface definition for the Object class.
type IProtocol ¶
type IProtocol interface { Handle Name() string MethodDescription(sel Selector, required bool, instanceMethod bool) MethodDescription CopyMethodDescriptionList(required bool, instanceMethod bool) []MethodDescription CopyProtocolList() []Protocol Property(name string, required bool, isInstanceProperty bool) Property CopyPropertyList() []Property }
type Method ¶
type Method struct {
// contains filtered or unexported fields
}
func (Method) Implementation ¶
func (Method) SetImplementation ¶
func (Method) TypeEncoding ¶
type MethodDescription ¶
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
The root class of most Objective-C class hierarchies, from which subclasses inherit a basic interface to the runtime system and the ability to behave as Objective-C objects. Full Topic
func GetAssociatedObject ¶
Returns the value associated with a given object for a given key. Full Topic
func WrapAsProtocol ¶
func (Object) Autorelease ¶
Decrements the receiver’s retain count at the end of the current autorelease pool block. Full Topic
func (Object) Class ¶
Returns the class object for the receiver’s class. Full Topic
func (Object) ConformsToProtocol ¶
Returns a Boolean value that indicates whether the receiver conforms to a given protocol. Full Topic
func (Object) Dealloc ¶
func (o Object) Dealloc()
Deallocates the memory occupied by the receiver. Full Topic
func (Object) Description ¶
Returns a string that represents the contents of the receiving class. Full Topic
func (Object) IsKindOfClass ¶
Returns a Boolean value that indicates whether the receiver is an instance of given class or an instance of any class that inherits from that class. Full Topic
func (Object) IsMemberOfClass ¶
Returns a Boolean value that indicates whether the receiver is an instance of a given class. Full Topic
func (Object) IsProxy ¶
Returns a Boolean value that indicates whether the receiver does not descend from NSObject. Full Topic
func (Object) PerformSelector ¶
Sends a specified message to the receiver and returns the result of the message. Full Topic
func (Object) PerformSelectorWithObject ¶
Sends a message to the receiver with an object as the argument. Full Topic
func (Object) PerformSelectorWithObjectWithObject ¶
Sends a message to the receiver with two objects as arguments. Full Topic
func (Object) Release ¶
func (o Object) Release()
Decrements the receiver’s reference count. Full Topic
func (Object) RespondsToSelector ¶
Returns a Boolean value that indicates whether the receiver implements or inherits a method that can respond to a specified message. Full Topic
func (Object) Retain ¶
Increments the receiver’s reference count. Full Topic
type Property ¶
type Property struct {
// contains filtered or unexported fields
}
func (Property) Attributes ¶
func (Property) CopyAttributeList ¶
func (p Property) CopyAttributeList() []PropertyAttribute
func (Property) CopyAttributeValue ¶
type PropertyAttribute ¶
type Protocol ¶
type Protocol struct {
// contains filtered or unexported fields
}
func AllocateProtocol ¶
func GetProtocol ¶
func (Protocol) CopyMethodDescriptionList ¶
func (p Protocol) CopyMethodDescriptionList(required bool, instanceMethod bool) []MethodDescription
func (Protocol) CopyPropertyList ¶
func (Protocol) CopyProtocolList ¶
func (Protocol) MethodDescription ¶
func (p Protocol) MethodDescription(sel Selector, required bool, instanceMethod bool) MethodDescription
type Selector ¶
type Selector struct {
// contains filtered or unexported fields
}
func RegisterSelectorName ¶
RegisterSelectorName registers a method with the Objective-C runtime system, maps the method name to a selector, and returns the selector value.
func SelectorFrom ¶
type SyncCache ¶
type SyncCache[K comparable, V any] struct { // contains filtered or unexported fields }
type UserClass ¶
UserClass is a generic wrapper around Class returned by NewClass.