Documentation
¶
Overview ¶
Package rt holds small runtime helpers shared by the generated Go APIs and available for your own code to use as well. They cover the recurring jobs of calling Objective-C from Go: turning a callback-style Objective-C call into a blocking Go call, converting between Objective-C collections/data and Go slices/maps/bytes, asking an object about its type, and reporting a "not found" lookup as a Go (value, ok) pair.
Index ¶
- Constants
- func Await(ctx context.Context, start func(done func(error))) error
- func AwaitValue[T any](ctx context.Context, start func(done func(T, error))) (T, error)
- func BytesToNSData(b []byte) objc.ID
- func ClassNameOf(id objc.ID) string
- func Description(id objc.ID) string
- func DictToMap[K comparable, V any](dict objc.ID, kconv func(objc.ID) K, vconv func(objc.ID) V) map[K]V
- func FileURL(path string) objc.ID
- func IndexResult(raw uint) (int, bool)
- func IsEqual(a, b objc.ID) bool
- func IsKind(id objc.ID, className string) bool
- func MapToDict[K comparable, V any](m map[K]V, kconv func(K) objc.ID, vconv func(V) objc.ID) objc.ID
- func NSDataToBytes(id objc.ID) []byte
- func NSDateToTime(id objc.ID) time.Time
- func NSSetToSlice[T any](set objc.ID, conv func(objc.ID) T) []T
- func SliceToNSSet[T any](items []T, conv func(T) objc.ID) objc.ID
- func TimeToNSDate(t time.Time) objc.ID
- func URLString(id objc.ID) string
Constants ¶
const NSNotFound = int(^uint(0) >> 1)
NSNotFound is Foundation's "no index" sentinel (NSIntegerMax). The idiomatic layer never exposes it; index lookups return (int, bool) via IndexResult.
Variables ¶
This section is empty.
Functions ¶
func Await ¶
Await turns an Objective-C method that reports completion through a callback into an ordinary blocking Go call that returns an error. You pass a start function that kicks off the work and calls done(err) when the callback fires; Await waits for that, or returns early if ctx is cancelled. Cancelling ctx only stops Await from waiting — it does not cancel the Objective-C work already in progress.
func AwaitValue ¶
AwaitValue is Await for a completion handler that also yields a result value.
func BytesToNSData ¶
BytesToNSData builds an autoreleased NSData from a Go byte slice (copying the bytes). An empty slice yields an empty NSData.
func ClassNameOf ¶
ClassNameOf returns the runtime class name of an object ("" for nil), via object_getClassName from libobjc.
func Description ¶
Description returns the object's -description as a Go string ("" for nil).
func DictToMap ¶
func DictToMap[K comparable, V any](dict objc.ID, kconv func(objc.ID) K, vconv func(objc.ID) V) map[K]V
DictToMap converts an NSDictionary to a Go map, mapping each key/value id through the supplied converters. Returns nil for a nil or empty dictionary.
func FileURL ¶
FileURL returns an Objective-C file URL (NSURL) for a filesystem path. Many Objective-C methods take a file URL rather than a path string; the generated code accepts a Go string and calls this to build the URL.
func IndexResult ¶
IndexResult converts a raw NSUInteger index result into the idiomatic (int, bool) shape: ok is false when the call returned NSNotFound.
func IsEqual ¶
IsEqual reports whether two objects are equal (isEqual:). Two nil objects are equal; a nil and a non-nil object are not.
func IsKind ¶
IsKind reports whether the object is an instance of the named class or a subclass (isKindOfClass:). Returns false for a nil object or unknown class.
func MapToDict ¶
func MapToDict[K comparable, V any](m map[K]V, kconv func(K) objc.ID, vconv func(V) objc.ID) objc.ID
MapToDict builds an autoreleased NSMutableDictionary from a Go map.
func NSDataToBytes ¶
NSDataToBytes copies the contents of an NSData object into a new Go byte slice. Returns nil for a nil or empty NSData.
func NSDateToTime ¶
NSDateToTime converts an NSDate to a Go time.Time (the zero time.Time for nil). NSDate stores seconds as a float64, so values keep sub-microsecond — not full nanosecond — precision.
func NSSetToSlice ¶
NSSetToSlice converts an NSSet to a Go slice (order unspecified). Returns nil for a nil or empty set.
func SliceToNSSet ¶
SliceToNSSet builds an autoreleased NSMutableSet from a Go slice.
func TimeToNSDate ¶
TimeToNSDate builds an autoreleased NSDate from a Go time.Time. The zero time.Time yields a nil NSDate, so it round-trips with NSDateToTime.
Types ¶
This section is empty.