objc: NSString type + Into(*NSString) for string
Adds an NSString foreign class and impl Into(*NSString) for string so a string literal flows into any *NSString slot via xx. uikit's keyboard userInfo lookups now read objectForKey(xx "...") instead of ns_string("...".ptr), and objectForKey's key param is retyped *NSString.
ffi-objc-call-06 .ir snapshot regenerated: declaring the NSString type adds its reflection thunks (struct_to_string/pointer_to_string), same as the existing NSObject/NSDictionary. Runtime output unchanged.
This commit is contained in:
@@ -123,6 +123,24 @@ NSObject :: #foreign #objc_class("NSObject") {
|
||||
respondsToSelector :: (self: *Self, sel: *void) -> BOOL;
|
||||
}
|
||||
|
||||
// ─── NSString ────────────────────────────────────────────────────────────
|
||||
// Foundation's immutable string. `ns_string` builds an autoreleased instance
|
||||
// from a C string; the `Into` impl lets a string literal flow into any
|
||||
// `*NSString` slot via `xx`, e.g. `dict.objectForKey(xx "SomeKey")`.
|
||||
NSString :: #foreign #objc_class("NSString") {
|
||||
#extends NSObject;
|
||||
UTF8String :: (self: *Self) -> [*]u8;
|
||||
}
|
||||
|
||||
// `self.ptr` must be NUL-terminated. String literals are; an arbitrary
|
||||
// substring/built `string` may not be, so only pass literals (or otherwise
|
||||
// NUL-terminated slices) through this conversion.
|
||||
impl Into(*NSString) for string {
|
||||
convert :: (self: string) -> *NSString {
|
||||
return xx ns_string(self.ptr);
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Autoreleasepool (M4.A) ──────────────────────────────────────────────
|
||||
// Foundation factory methods (`NSString.stringWithUTF8String:`,
|
||||
// `[NSArray array]`, ...) return autoreleased objects — valid until the
|
||||
|
||||
Reference in New Issue
Block a user