define_class!( // SAFETY: // - The superclass NSObject does not have any subclassing requirements. // - `Delegate` does not implement `Drop`. #[unsafe(super = NSObject)] #[thread_kind = MainThreadOnly] #[ivars = AppDelegateIvars] struct Delegate;
// SAFETY: `NSObjectProtocol` has no safety requirements. unsafeimpl NSObjectProtocol for Delegate {}
// SAFETY: `NSApplicationDelegate` has no safety requirements. unsafeimpl NSApplicationDelegate for Delegate { // SAFETY: The signature is correct. #[unsafe(method(applicationDidFinishLaunching:))] fn did_finish_launching(&self, notification: &NSNotification) { let mtm = self.mtm();
let app = unsafe { notification.object() }
.unwrap()
.downcast::<NSApplication>()
.unwrap();
// Activate the application. // Required when launching unbundled (as is done with Cargo). #[allow(deprecated)]
app.activateIgnoringOtherApps(true);
}
}
// SAFETY: `NSWindowDelegate` has no safety requirements. unsafeimpl NSWindowDelegate for Delegate { #[unsafe(method(windowWillClose:))] fn window_will_close(&self, _notification: &NSNotification) { // Quit the application when the window is closed. unsafe { NSApplication::sharedApplication(self.mtm()).terminate(None) };
}
}
);
impl Delegate { fn new(mtm: MainThreadMarker) -> Retained<Self> { let this = Self::alloc(mtm).set_ivars(AppDelegateIvars::default()); // SAFETY: The signature of `NSObject`'s `init` method is correct. unsafe { msg_send![super(this), init] }
}
}
fn main() { let mtm = MainThreadMarker::new().unwrap();
let app = NSApplication::sharedApplication(mtm); let delegate = Delegate::new(mtm);
app.setDelegate(Some(ProtocolObject::from_ref(&*delegate)));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.