objcjs-types 0.6.3 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +42 -8
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -108,6 +108,39 @@ if (isKindOfClass<_ASAuthorizationAppleIDCredential>(cred, ASAuthorizationAppleI
108
108
 
109
109
  Both `instanceof` and `isKindOfClass` cache results per (object, class) pair so repeated checks skip the native boundary.
110
110
 
111
+ ### Subclassing
112
+
113
+ `defineSubclass` wraps `NobjcClass.define()` with type safety — `self` is typed as the superclass, protocol method names get autocomplete, and the returned class supports `alloc`/`init` and `instanceof`:
114
+
115
+ ```ts
116
+ import { NSObject } from "objcjs-types/Foundation";
117
+ import { defineSubclass, callSuper } from "objcjs-types/subclass";
118
+
119
+ const MyDelegate = defineSubclass(NSObject, {
120
+ name: "MyDelegate",
121
+ protocols: ["NSWindowDelegate"],
122
+ methods: {
123
+ windowDidResize$: {
124
+ types: "v@:@",
125
+ implementation(self, notification) {
126
+ console.log("Resized!");
127
+ }
128
+ },
129
+ init: {
130
+ types: "@@:",
131
+ implementation(self) {
132
+ return callSuper(self, "init");
133
+ }
134
+ }
135
+ }
136
+ });
137
+
138
+ const instance = MyDelegate.alloc().init();
139
+ window.setDelegate$(instance);
140
+ ```
141
+
142
+ Use `callSuper` inside method implementations to invoke the superclass version of a method.
143
+
111
144
  ### NS_OPTIONS
112
145
 
113
146
  Use `options()` to combine bitmask flags with type safety:
@@ -175,14 +208,15 @@ const nsStr = NSStringFromString("hello");
175
208
 
176
209
  ## Subpath exports
177
210
 
178
- | Import path | Contents |
179
- | -------------------------- | ------------------------------------------------------ |
180
- | `objcjs-types` | Structs, `createDelegate`, barrel re-exports |
181
- | `objcjs-types/helpers` | `NSStringFromString`, `options`, `isKindOfClass`, etc. |
182
- | `objcjs-types/nsdata` | NSData/Buffer conversion utilities |
183
- | `objcjs-types/osversion` | macOS version detection and comparison |
184
- | `objcjs-types/delegates` | `createDelegate` and `ProtocolMap` type |
185
- | `objcjs-types/<Framework>` | Framework exports (e.g. `objcjs-types/AppKit`) |
211
+ | Import path | Contents |
212
+ | -------------------------- | -------------------------------------------------------- |
213
+ | `objcjs-types` | Structs, `createDelegate`, `defineSubclass`, `callSuper` |
214
+ | `objcjs-types/helpers` | `NSStringFromString`, `options`, `isKindOfClass`, etc. |
215
+ | `objcjs-types/subclass` | `defineSubclass`, `callSuper` |
216
+ | `objcjs-types/nsdata` | NSData/Buffer conversion utilities |
217
+ | `objcjs-types/osversion` | macOS version detection and comparison |
218
+ | `objcjs-types/delegates` | `createDelegate` and `ProtocolMap` type |
219
+ | `objcjs-types/<Framework>` | Framework exports (e.g. `objcjs-types/AppKit`) |
186
220
 
187
221
  ## ObjC selector naming
188
222
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "objcjs-types",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "description": "Auto-generated TypeScript type declarations for macOS Objective-C frameworks that supplement objc-js",
5
5
  "type": "module",
6
6
  "sideEffects": false,