Documentation
¶
Overview ¶
Package obj defines Object, a Go handle for an Objective-C object whose specific type is not known. Some Objective-C APIs hand back a plain object ("id") — for example an element read from an untyped collection — and the generated code represents those as an Object.
Every generated wrapper type (String, VirtualMachine, and so on) is also an Object, so a specific wrapper can be passed anywhere an Object is expected. Going the other way, IsKind reports an object's Objective-C class, which lets you safely convert an Object to the specific wrapper you expect.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func As ¶
As narrows an Object to a specific wrapper type, after checking the object's Objective-C class. It is the idiomatic way to recover a typed value from an "id" return — for example an element read from an untyped dictionary:
dict, ok := obj.As(value, "NSDictionary", foundation.DictionaryFromID)
fromID is the wrapper type's generated FromID constructor. ok is false (and the result the type's zero value) when o is nil or is not an instance of className.
func Bytes ¶
Bytes copies the contents of an NSData object into a Go byte slice. It returns nil when o is nil. Use it to read the bytes of an NSData handed back as an Object (for example a value read from a dictionary).
func ID ¶
ID returns the underlying Objective-C object pointer of o (0 when o is nil).
This is the deliberate escape hatch for advanced interoperation the generated API cannot express — sending a selector by hand, installing a custom delegate implemented as a runtime class, or any other direct Objective-C dispatch. It does NOT expose the raw bindings, so a package using it stays free of the bindings/frameworks dependency; prefer the generated methods wherever they suffice and reach for ID only for genuine custom Objective-C work.
Types ¶
type Object ¶
type Object interface {
objref.Object
// Description returns the object's human-readable description text (the
// result of Objective-C's -description).
Description() string
// IsEqual reports whether this object is equal to another, as Objective-C
// itself decides (its -isEqual: method).
IsEqual(other Object) bool
// IsKind reports whether the object is an instance of the named Objective-C
// class, or of a subclass of it. Use it to check an object's type before
// converting it to a specific wrapper.
IsKind(className string) bool
// Release relinquishes the Go side's reference to the object immediately,
// instead of waiting for the garbage collector. Idempotent; after Release
// the object's methods are no-ops returning zero values.
Release()
}
Object is a Go handle for an Objective-C object.
Only types that embed an objref.Handle can satisfy Object (the embedded interface has an unexported method), and the Handle supplies Release — so every implementation, generated or hand-written, gets the same lifecycle behavior.
func Adopt ¶
Adopt returns an Object for an Objective-C object the caller already owns a reference to — for example the result of a create function annotated OS_OBJECT_RETURNS_RETAINED, or any other +1 result. Unlike Wrap it does NOT retain the object; it only arranges the matching release once Go stops using it. Wrapping an already-retained result with Wrap would leak one reference.