-
Notifications
You must be signed in to change notification settings - Fork 63
Open
Labels
A-objc2Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` cratesAffects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` cratesbugSomething isn't workingSomething isn't working
Milestone
Description
Hi! I have a problem with debug build my application.
If i build app in debug mode i have an error in runtime:
thread 'main' panicked at /Users/username/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/objc2-0.6.2/src/__macro_helpers/define_class.rs:328:21:
failed overriding protocol method -[NSWindowDelegate canBecomeKeyWindow]: method not found
Error here:
#[cfg(debug_assertions)]
if let Some(protocol) = self.protocol {
let _types = self
.required_instance_methods
.iter()
.chain(&self.optional_instance_methods)
.find(|desc| desc.sel == sel)
.map(|desc| desc.types)
.unwrap_or_else(|| {
panic!(
"failed overriding protocol method -[{protocol} {sel}]: method not found"
)
});
}
My code:
pub struct WindowState {}
define_class!(
#[unsafe(super = NSWindow)]
#[ivars = WindowState]
#[thread_kind = MainThreadOnly]
pub struct Window;
unsafe impl NSObjectProtocol for Window {}
unsafe impl NSWindowDelegate for Window {
#[unsafe(method(canBecomeKeyWindow))]
fn can_become_key_window(&self) -> bool {
true
}
}
);
Am I doing something wrong?
In release mode all works fine.
System info:
Macbook Pro (Apple M3 Pro)
macOS Tahoe 26.0.1
rustc 1.89.0 (29483883e 2025-08-04)
cargo 1.89.0 (c24e10642 2025-06-23)
Libs:
objc2 = "0.6.1"
objc2-foundation = { version = "0.3.1", features = [
"NSEnumerator",
"NSThread",
] }
objc2-app-kit = { version = "0.3.1", features = [
"NSApplication",
"NSEvent",
"NSGraphicsContext",
"NSResponder",
"NSRunningApplication",
"NSView",
"NSWindow",
"NSWindowScripting",
"NSTrackingArea",
"NSCursor",
] }
objc2-core-foundation = { version = "0.3.1" }
objc2-core-graphics = { version = "0.3.1" }
dispatch2 = { version = "0.3.0" }
Metadata
Metadata
Assignees
Labels
A-objc2Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` cratesAffects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` cratesbugSomething isn't workingSomething isn't working