CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pyobjc-core

Python-to-Objective-C bridge providing seamless interoperability between Python and Objective-C programming languages on macOS systems.

Pending
Overview
Eval results
Files

method-decorators.mddocs/

Method and Class Decorators

Decorators for controlling how Python methods are exposed to the Objective-C runtime, including method signatures, selector customization, and method classification.

Capabilities

Method Classification Decorators

Decorators that control whether methods are exposed to the Objective-C runtime or kept as Python-only methods.

def objc_method(value=None, *, selector=None, signature=None, isclass=None):
    """
    Decorator to mark methods as Objective-C selectors.
    
    Args:
        value: Method to decorate (when used without parentheses)
        selector (str, optional): Override Objective-C selector name
        signature (bytes, optional): Method signature in Objective-C encoding
        isclass (bool, optional): True for class methods, False for instance methods
        
    Returns:
        Decorated method exposed to Objective-C runtime
    """

def python_method(value=None):
    """
    Decorator to mark methods as Python-only (not Objective-C selectors).
    
    Args:
        value: Method to decorate
        
    Returns:
        Method that won't be exposed to Objective-C runtime
    """

Selector Customization

Decorators for customizing Objective-C selector names and method signatures.

def namedSelector(name, signature=None):
    """
    Override the Objective-C selector name for a method.
    
    Args:
        name (str): Objective-C selector name
        signature (bytes, optional): Method signature in Objective-C encoding
        
    Returns:
        Decorator function
    """

def namedselector(name, signature=None):
    """
    Alias for namedSelector.
    
    Args:
        name (str): Objective-C selector name  
        signature (bytes, optional): Method signature in Objective-C encoding
        
    Returns:
        Decorator function
    """

def typedSelector(signature):
    """
    Decorator for specifying typed selectors with explicit signatures.
    
    Args:
        signature (bytes): Method signature in Objective-C encoding
        
    Returns:
        Decorator function
    """

Method Signature Control

Functions for setting and managing method signatures in the Objective-C runtime.

def signature(sig):
    """
    Set method signature for Objective-C method.
    
    Args:
        sig (bytes): Method signature in Objective-C encoding
        
    Returns:
        Decorator function
    """

def instancemethod(func):
    """
    Mark function as an instance method.
    
    Args:
        func: Function to mark as instance method
        
    Returns:
        Decorated function
    """

Usage Examples:

import objc

class MyClass:
    @objc.objc_method
    def regularMethod(self):
        """This method will be available to Objective-C."""
        return "Hello from Objective-C"
    
    @objc.python_method
    def pythonOnlyMethod(self):
        """This method is Python-only."""
        return "Hello from Python"
    
    @objc.namedSelector("customSelectorName:")
    def renamedMethod_(self, value):
        """Method with custom Objective-C selector name."""
        return f"Value: {value}"
    
    @objc.objc_method(signature=b"i@:i")
    def integerMethod_(self, value):
        """Method with explicit signature (returns int, takes int)."""
        return value * 2
    
    @objc.objc_method(isclass=True)
    def classMethod(cls):
        """Class method exposed to Objective-C."""
        return "Class method result"

Install with Tessl CLI

npx tessl i tessl/pypi-pyobjc-core

docs

bridge-registration.md

class-enhancement.md

core-bridge.md

framework-loading.md

index.md

interface-builder.md

method-decorators.md

properties-accessors.md

protocol-support.md

pyobjctools.md

tile.json