or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

categories.mdcore-bridge.mddecorators.mdframework-loading.mdindex.mdprotocols.mdtype-system.mdutilities.md

core-bridge.mddocs/

0

# Core Bridge Functions

1

2

Fundamental bridge functionality that provides the foundation for all Python-Objective-C interoperability. These functions handle class lookup, runtime access, memory management, and bridge configuration.

3

4

## Capabilities

5

6

### Class and Object Management

7

8

Core functions for working with Objective-C classes and managing the bridge runtime environment.

9

10

```python { .api }

11

def lookUpClass(name: str):

12

"""

13

Look up an Objective-C class by name.

14

15

Args:

16

name (str): The name of the Objective-C class to find

17

18

Returns:

19

The Objective-C class object, or None if not found

20

"""

21

22

def getClassList():

23

"""

24

Get a list of all available Objective-C classes.

25

26

Returns:

27

list: List of all registered Objective-C classes

28

"""

29

30

def currentBundle():

31

"""

32

Get the current NSBundle object.

33

34

Returns:

35

NSBundle: The bundle object for the current application

36

"""

37

38

def loadBundle(path: str, module_globals: dict, bundle_identifier: str = None, scan_classes: bool = True):

39

"""

40

Load a framework bundle and make its classes available.

41

42

Args:

43

path (str): Path to the bundle to load

44

module_globals (dict): Global namespace to inject classes into

45

bundle_identifier (str, optional): Bundle identifier

46

scan_classes (bool): Whether to scan for classes in the bundle

47

48

Returns:

49

The loaded bundle object

50

"""

51

52

def pyobjc_id(obj):

53

"""

54

Get the Objective-C object ID for a bridged object.

55

56

Args:

57

obj: The object to get the ID for

58

59

Returns:

60

int: The object's unique identifier

61

"""

62

63

def repythonify(obj, strict: bool = True):

64

"""

65

Convert an Objective-C object to its Python representation.

66

67

Args:

68

obj: The Objective-C object to convert

69

strict (bool): Whether to use strict conversion rules

70

71

Returns:

72

The Python representation of the object

73

"""

74

75

options: object

76

"""

77

Bridge configuration options object.

78

79

Example:

80

objc.options.verbose = True # Enable verbose output

81

objc.options.verbose = False # Disable verbose output

82

"""

83

```

84

85

### Memory Management

86

87

Functions for managing Objective-C memory and autorelease pools.

88

89

```python { .api }

90

def recycleAutoreleasePool():

91

"""

92

Manually recycle the current autorelease pool.

93

94

This is typically handled automatically, but can be called

95

manually for fine-grained memory management control.

96

"""

97

98

def removeAutoreleasePool():

99

"""

100

Remove the current autorelease pool.

101

102

Lower-level pool management function. Use with caution.

103

"""

104

105

def setAssociatedObject(obj, key, value, policy):

106

"""

107

Associate an object with another object using a key.

108

109

Args:

110

obj: The object to associate with

111

key: The key for the association

112

value: The value to associate

113

policy: The association policy (retain, copy, etc.)

114

"""

115

116

def getAssociatedObject(obj, key):

117

"""

118

Get an associated object using a key.

119

120

Args:

121

obj: The object to query

122

key: The key for the association

123

124

Returns:

125

The associated value, or None if not found

126

"""

127

128

def _objc_sync_enter(obj):

129

"""

130

Enter a synchronized block on an object.

131

132

Args:

133

obj: The object to synchronize on

134

"""

135

136

def _objc_sync_exit(obj):

137

"""

138

Exit a synchronized block on an object.

139

140

Args:

141

obj: The object to synchronize on

142

"""

143

144

class autorelease_pool:

145

"""

146

Context manager for Objective-C autorelease pools.

147

148

Usage:

149

with objc.autorelease_pool():

150

# Objective-C operations that create autoreleased objects

151

pass

152

"""

153

def __enter__(self): ...

154

def __exit__(self, exc_type, exc_val, exc_tb): ...

155

```

156

157

### Runtime Access

158

159

Access to the Objective-C runtime system and core bridge objects.

160

161

```python { .api }

162

runtime: object

163

"""

164

Access to the Objective-C runtime system.

165

Provides low-level runtime introspection capabilities.

166

"""

167

168

class NSObject:

169

"""

170

Base class for Objective-C objects in Python.

171

172

All Objective-C classes accessible from Python inherit from this class.

173

Provides basic object lifecycle and introspection methods.

174

"""

175

```

176

177

### Method and Function Wrappers

178

179

Classes that wrap Objective-C methods and C functions for bridge usage.

180

181

```python { .api }

182

class selector:

183

"""

184

Represents Objective-C method selectors.

185

186

Selectors identify methods in the Objective-C runtime and are used

187

for method dispatch and introspection.

188

"""

189

190

class objc_method:

191

"""

192

Wraps Objective-C method implementations.

193

194

Provides access to method metadata, signatures, and implementation

195

details for bridged Objective-C methods.

196

"""

197

198

class function:

199

"""

200

Wraps C functions for bridge usage.

201

202

Enables calling C functions from Python with proper type conversion

203

and argument handling.

204

"""

205

206

class IMP:

207

"""

208

Method implementation pointer wrapper.

209

210

Represents the actual implementation function of an Objective-C method,

211

allowing direct method invocation bypass.

212

"""

213

214

class super:

215

"""

216

Override for Python's super() in Objective-C context.

217

218

Provides proper super method calling semantics when working with

219

Objective-C class hierarchies from Python.

220

"""

221

```

222

223

## Constants

224

225

```python { .api }

226

# Objective-C equivalents for common Python values

227

nil = None # Objective-C nil

228

YES = True # Objective-C YES

229

NO = False # Objective-C NO

230

```

231

232

## Exception Classes

233

234

```python { .api }

235

class error(Exception):

236

"""Base exception class for PyObjC errors."""

237

238

class nosuchclass_error(Exception):

239

"""Exception raised when an Objective-C class cannot be found."""

240

241

class internal_error(Exception):

242

"""Exception raised for internal bridge errors."""

243

```