objcbridge

package
v0.6.19 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package objcbridge contains small Objective-C runtime helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddMethods

func AddMethods(cls objc.Class, className string, methods []objc.MethodDef) error

AddMethods installs methods on cls.

Each method's Fn must take (objc.ID, objc.SEL) as its first two arguments; objc.NewIMP panics otherwise. See its documentation for why a missing prefix corrupts the call rather than failing it. AddMethods derives and records the Objective-C type encoding from Fn so signature-based dispatch sees the same arguments as the implementation.

func AddProtocols

func AddProtocols(cls objc.Class, className string, protocols []*objc.Protocol) error

AddProtocols declares that cls conforms to each protocol.

objc.RegisterClass takes protocols only when it creates a class, so a class that already exists -- one emitted statically into the binary, or registered by an earlier caller -- has no way to gain a conformance without this. The distinction is not cosmetic: frameworks dispatch on conformsToProtocol:, so a class carrying every required method but no conformance is rejected as if the methods were absent.

Adding a protocol a class already conforms to is a no-op, so this is safe to call more than once.

func ProtocolsByName

func ProtocolsByName(names ...string) []*objc.Protocol

ProtocolsByName resolves Objective-C protocols, skipping protocols not present on the running system.

func RequiredProtocolsByName

func RequiredProtocolsByName(names ...string) ([]*objc.Protocol, error)

RequiredProtocolsByName resolves Objective-C protocols and reports any missing protocol.

Types

type BlockInvoker

type BlockInvoker struct {
	// contains filtered or unexported fields
}

BlockInvoker invokes Objective-C blocks with known signatures.

If a typed shim is linked into the process, BlockInvoker uses that bridge; otherwise it falls back to the block's invoke pointer. Its methods return an error when block is nil or when the fallback invoke pointer cannot be resolved.

func NewBlockInvoker

func NewBlockInvoker() *BlockInvoker

NewBlockInvoker returns a block invoker with no linked shim names.

func NewBlockInvokerWithShims

func NewBlockInvokerWithShims(shims BlockShims) *BlockInvoker

NewBlockInvokerWithShims returns a block invoker that prefers linked typed shims when they are present.

func (*BlockInvoker) BoolError

func (r *BlockInvoker) BoolError(block objc.ID, value bool, errID objc.ID) error

BoolError invokes block(value, err).

func (*BlockInvoker) Error

func (r *BlockInvoker) Error(block objc.ID, errID objc.ID) error

Error invokes block(err).

func (*BlockInvoker) Object

func (r *BlockInvoker) Object(block objc.ID, object objc.ID) error

Object invokes block(object).

func (*BlockInvoker) ObjectError

func (r *BlockInvoker) ObjectError(block objc.ID, object objc.ID, errID objc.ID) error

ObjectError invokes block(object, err).

func (*BlockInvoker) ObjectObject

func (r *BlockInvoker) ObjectObject(block objc.ID, a objc.ID, b objc.ID) error

ObjectObject invokes block(a, b).

func (*BlockInvoker) ObjectObjectError

func (r *BlockInvoker) ObjectObjectError(block objc.ID, a objc.ID, b objc.ID, errID objc.ID) error

ObjectObjectError invokes block(a, b, err).

func (*BlockInvoker) Uint

func (r *BlockInvoker) Uint(block objc.ID, value uint) error

Uint invokes block(value).

func (*BlockInvoker) Uint64Error

func (r *BlockInvoker) Uint64Error(block objc.ID, value uint64, errID objc.ID) error

Uint64Error invokes block(value, err).

func (*BlockInvoker) UintptrError

func (r *BlockInvoker) UintptrError(block objc.ID, value uintptr, errID objc.ID) error

UintptrError invokes block(value, err).

func (*BlockInvoker) Void

func (r *BlockInvoker) Void(block objc.ID) error

Void invokes block().

type BlockShims

type BlockShims struct {
	Error             string
	Object            string
	ObjectObject      string
	Uint              string
	ObjectError       string
	ObjectObjectError string
	Uint64Error       string
	BoolError         string
	UintptrError      string
}

BlockShims names optional linked functions used for typed block invocation.

Jump to

Keyboard shortcuts

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