or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

bridge-registration.mdclass-enhancement.mdcore-bridge.mdframework-loading.mdindex.mdinterface-builder.mdmethod-decorators.mdproperties-accessors.mdprotocol-support.mdpyobjctools.md

bridge-registration.mddocs/

0

# Bridge Registration and Type System

1

2

Functions for registering Python types with the bridge system and comprehensive SIMD type support, enabling seamless integration between Python data types and Objective-C collections and high-performance operations.

3

4

## Capabilities

5

6

### Collection Type Registration

7

8

Functions for registering Python types to work seamlessly with Objective-C collection classes.

9

10

```python { .api }

11

def registerListType(type_object):

12

"""

13

Register a list-like type for NSMutableArray proxying.

14

15

Args:

16

type_object: Python type that behaves like a list

17

18

Enables automatic conversion between the Python type and NSMutableArray.

19

"""

20

21

def registerMappingType(type_object):

22

"""

23

Register a dict-like type for NSMutableDictionary proxying.

24

25

Args:

26

type_object: Python type that behaves like a dictionary

27

28

Enables automatic conversion between the Python type and NSMutableDictionary.

29

"""

30

31

def registerSetType(type_object):

32

"""

33

Register a set-like type for NSMutableSet proxying.

34

35

Args:

36

type_object: Python type that behaves like a set

37

38

Enables automatic conversion between the Python type and NSMutableSet.

39

"""

40

```

41

42

### Specialized Type Registration

43

44

Functions for registering specialized Python types with corresponding Objective-C classes.

45

46

```python { .api }

47

def registerDateType(type_object):

48

"""

49

Register a date-like type for NSDate proxying.

50

51

Args:

52

type_object: Python type that represents dates/times

53

54

Enables automatic conversion between the Python type and NSDate.

55

"""

56

57

def registerPathType(type_object):

58

"""

59

Register a path-like type for filesystem path handling.

60

61

Args:

62

type_object: Python type that represents filesystem paths

63

64

Enables proper path handling with Objective-C path-related APIs.

65

"""

66

```

67

68

### SIMD Vector Types

69

70

Comprehensive SIMD vector types for high-performance mathematical operations.

71

72

```python { .api }

73

# Integer vectors

74

simd_int2: type # 2-component integer vector

75

simd_int3: type # 3-component integer vector

76

simd_int4: type # 4-component integer vector

77

simd_uint2: type # 2-component unsigned integer vector

78

simd_uint3: type # 3-component unsigned integer vector

79

80

# Short vectors

81

simd_short2: type # 2-component short vector

82

simd_ushort2: type # 2-component unsigned short vector

83

simd_ushort3: type # 3-component unsigned short vector

84

simd_ushort4: type # 4-component unsigned short vector

85

86

# Character vectors

87

simd_uchar16: type # 16-component unsigned char vector

88

89

# Float vectors

90

simd_float2: type # 2-component float vector

91

simd_float3: type # 3-component float vector

92

simd_float4: type # 4-component float vector

93

94

# Double vectors

95

simd_double2: type # 2-component double vector

96

simd_double3: type # 3-component double vector

97

simd_double4: type # 4-component double vector

98

99

# Quaternions

100

simd_quatf: type # Float quaternion

101

simd_quatd: type # Double quaternion

102

103

# Vector aliases (compatible with Metal and other frameworks)

104

vector_float2: type # Alias for simd_float2

105

vector_float3: type # Alias for simd_float3

106

vector_float4: type # Alias for simd_float4

107

vector_double2: type # 2-component double vector

108

vector_double3: type # 3-component double vector

109

vector_double4: type # 4-component double vector

110

vector_short2: type # 2-component short vector

111

vector_ushort2: type # 2-component unsigned short vector

112

vector_ushort3: type # 3-component unsigned short vector

113

vector_ushort4: type # 4-component unsigned short vector

114

vector_int2: type # 2-component integer vector

115

vector_int3: type # 3-component integer vector

116

vector_int4: type # 4-component integer vector

117

vector_uint2: type # 2-component unsigned integer vector

118

vector_uint3: type # 3-component unsigned integer vector

119

vector_uchar16: type # 16-component unsigned char vector

120

```

121

122

### SIMD Matrix Types

123

124

Matrix types for 3D graphics and mathematical operations.

125

126

```python { .api }

127

# Float matrices

128

matrix_float2x2: type # 2x2 float matrix

129

matrix_float3x3: type # 3x3 float matrix

130

matrix_float4x3: type # 4x3 float matrix

131

matrix_float4x4: type # 4x4 float matrix

132

simd_float4x4: type # Alias for matrix_float4x4

133

134

# Double matrices

135

matrix_double4x4: type # 4x4 double matrix

136

```

137

138

**Usage Examples:**

139

140

```python

141

import objc

142

from objc import (registerListType, registerMappingType, registerSetType,

143

registerDateType, simd_float3, matrix_float4x4)

144

145

# Register custom collection types

146

class MyCustomList:

147

def __init__(self):

148

self.items = []

149

150

def append(self, item):

151

self.items.append(item)

152

153

def __len__(self):

154

return len(self.items)

155

156

# Register with bridge for automatic NSMutableArray conversion

157

registerListType(MyCustomList)

158

159

# Register custom mapping type

160

class MyCustomDict:

161

def __init__(self):

162

self.data = {}

163

164

def __setitem__(self, key, value):

165

self.data[key] = value

166

167

def __getitem__(self, key):

168

return self.data[key]

169

170

registerMappingType(MyCustomDict)

171

172

# Using SIMD types for high-performance operations

173

position = simd_float3(1.0, 2.0, 3.0) # 3D position vector

174

175

# 4x4 transformation matrix for 3D graphics

176

transform = matrix_float4x4([

177

[1.0, 0.0, 0.0, 0.0],

178

[0.0, 1.0, 0.0, 0.0],

179

[0.0, 0.0, 1.0, 0.0],

180

[0.0, 0.0, 0.0, 1.0]

181

])

182

183

# SIMD types work seamlessly with Metal, SceneKit, and other frameworks

184

# that expect vectorized data types

185

```

186

187

### Integration with Objective-C Frameworks

188

189

The registered types and SIMD support enable seamless integration with:

190

191

- **Collections**: Automatic bridging between Python and NSArray/NSDictionary/NSSet

192

- **Graphics**: SIMD types work with Metal, Core Graphics, and SceneKit

193

- **Game Development**: Vector and matrix types for 3D transformations

194

- **Scientific Computing**: High-performance mathematical operations

195

- **Framework APIs**: Direct compatibility with framework methods expecting specific types

196

197

### Type Safety and Performance

198

199

- **Automatic Conversion**: Registered types are automatically converted when crossing the Python-Objective-C boundary

200

- **Performance Optimization**: SIMD types provide hardware-accelerated operations

201

- **Type Validation**: Bridge ensures type compatibility and proper conversion

202

- **Memory Efficiency**: Direct memory mapping for SIMD operations where possible