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:
@@ -75,7 +75,7 @@ NSNumber :: #foreign #objc_class("NSNumber") {
|
|||||||
|
|
||||||
NSDictionary :: #foreign #objc_class("NSDictionary") {
|
NSDictionary :: #foreign #objc_class("NSDictionary") {
|
||||||
#extends NSObject;
|
#extends NSObject;
|
||||||
objectForKey :: (self: *Self, key: *void) -> *void;
|
objectForKey :: (self: *Self, key: *NSString) -> *void;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSMutableDictionary :: #foreign #objc_class("NSMutableDictionary") {
|
NSMutableDictionary :: #foreign #objc_class("NSMutableDictionary") {
|
||||||
@@ -563,19 +563,19 @@ impl Platform for UIKitPlatform {
|
|||||||
user_info := notification.userInfo();
|
user_info := notification.userInfo();
|
||||||
if user_info == null { return; }
|
if user_info == null { return; }
|
||||||
|
|
||||||
end_value_raw := user_info.objectForKey(ns_string("UIKeyboardFrameEndUserInfoKey".ptr));
|
end_value_raw := user_info.objectForKey(xx "UIKeyboardFrameEndUserInfoKey");
|
||||||
if end_value_raw == null { return; }
|
if end_value_raw == null { return; }
|
||||||
end_value : *NSValue = xx end_value_raw;
|
end_value : *NSValue = xx end_value_raw;
|
||||||
end_rect := end_value.CGRectValue();
|
end_rect := end_value.CGRectValue();
|
||||||
|
|
||||||
dur_value_raw := user_info.objectForKey(ns_string("UIKeyboardAnimationDurationUserInfoKey".ptr));
|
dur_value_raw := user_info.objectForKey(xx "UIKeyboardAnimationDurationUserInfoKey");
|
||||||
anim_dur : f64 = 0.0;
|
anim_dur : f64 = 0.0;
|
||||||
if dur_value_raw != null {
|
if dur_value_raw != null {
|
||||||
dur_value : *NSNumber = xx dur_value_raw;
|
dur_value : *NSNumber = xx dur_value_raw;
|
||||||
anim_dur = dur_value.doubleValue();
|
anim_dur = dur_value.doubleValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
curve_value_raw := user_info.objectForKey(ns_string("UIKeyboardAnimationCurveUserInfoKey".ptr));
|
curve_value_raw := user_info.objectForKey(xx "UIKeyboardAnimationCurveUserInfoKey");
|
||||||
curve_int : u64 = 0;
|
curve_int : u64 = 0;
|
||||||
if curve_value_raw != null {
|
if curve_value_raw != null {
|
||||||
curve_value : *NSNumber = xx curve_value_raw;
|
curve_value : *NSNumber = xx curve_value_raw;
|
||||||
|
|||||||
@@ -123,6 +123,24 @@ NSObject :: #foreign #objc_class("NSObject") {
|
|||||||
respondsToSelector :: (self: *Self, sel: *void) -> BOOL;
|
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) ──────────────────────────────────────────────
|
// ─── Autoreleasepool (M4.A) ──────────────────────────────────────────────
|
||||||
// Foundation factory methods (`NSString.stringWithUTF8String:`,
|
// Foundation factory methods (`NSString.stringWithUTF8String:`,
|
||||||
// `[NSArray array]`, ...) return autoreleased objects — valid until the
|
// `[NSArray array]`, ...) return autoreleased objects — valid until the
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user