rt

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Rendered for darwin/amd64

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

View Source
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

func Await(ctx context.Context, start func(done func(error))) error

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

func AwaitValue[T any](ctx context.Context, start func(done func(T, error))) (T, error)

AwaitValue is Await for a completion handler that also yields a result value.

func BytesToNSData

func BytesToNSData(b []byte) objc.ID

BytesToNSData builds an autoreleased NSData from a Go byte slice (copying the bytes). An empty slice yields an empty NSData.

func ClassNameOf

func ClassNameOf(id objc.ID) string

ClassNameOf returns the runtime class name of an object ("" for nil), via object_getClassName from libobjc.

func Description

func Description(id objc.ID) string

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

func FileURL(path string) objc.ID

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

func IndexResult(raw uint) (int, bool)

IndexResult converts a raw NSUInteger index result into the idiomatic (int, bool) shape: ok is false when the call returned NSNotFound.

func IsEqual

func IsEqual(a, b objc.ID) bool

IsEqual reports whether two objects are equal (isEqual:). Two nil objects are equal; a nil and a non-nil object are not.

func IsKind

func IsKind(id objc.ID, className string) bool

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

func NSDataToBytes(id objc.ID) []byte

NSDataToBytes copies the contents of an NSData object into a new Go byte slice. Returns nil for a nil or empty NSData.

func NSDateToTime

func NSDateToTime(id objc.ID) time.Time

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

func NSSetToSlice[T any](set objc.ID, conv func(objc.ID) T) []T

NSSetToSlice converts an NSSet to a Go slice (order unspecified). Returns nil for a nil or empty set.

func SliceToNSSet

func SliceToNSSet[T any](items []T, conv func(T) objc.ID) objc.ID

SliceToNSSet builds an autoreleased NSMutableSet from a Go slice.

func TimeToNSDate

func TimeToNSDate(t time.Time) objc.ID

TimeToNSDate builds an autoreleased NSDate from a Go time.Time. The zero time.Time yields a nil NSDate, so it round-trips with NSDateToTime.

func URLString

func URLString(id objc.ID) string

URLString returns the Go string form of an NSURL: the filesystem path for a file URL (so it round-trips through FileURL), the absolute URL string for anything else, and "" for nil.

Types

This section is empty.

Jump to

Keyboard shortcuts

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