#[repr(C)]pub(crate) struct AppDelegate {
__superclass: ManuallyDrop<<NSObject as ClassType>::__SubclassingType>,
__phantom: PhantomData<(<Self as DefinedClass>::Ivars, ThreadKindAutoTraits<<Self as ClassType>::ThreadKind>)>,
}Fields§
§__superclass: ManuallyDrop<<NSObject as ClassType>::__SubclassingType>§__phantom: PhantomData<(<Self as DefinedClass>::Ivars, ThreadKindAutoTraits<<Self as ClassType>::ThreadKind>)>Implementations§
Source§impl AppDelegate
impl AppDelegate
Sourceextern "C-unwind" fn did_finish_launching(
&self,
_: Sel,
_notification: <&NSNotification as ConvertArgument>::__Inner,
)
extern "C-unwind" fn did_finish_launching( &self, _: Sel, _notification: <&NSNotification as ConvertArgument>::__Inner, )
Apps launched from a terminal start in the background unless activated.
extern "C-unwind" fn should_terminate_after_last_window_closed( &self, _: Sel, _sender: <&NSApplication as ConvertArgument>::__Inner, ) -> <bool as ConvertReturn<()>>::Inner
Source§impl AppDelegate
impl AppDelegate
pub(crate) fn new(mtm: MainThreadMarker) -> Retained<Self> ⓘ
Methods from Deref<Target = NSObject>§
Sourcepub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
pub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
Handle messages the object doesn’t recognize.
See Apple’s documentation for details.
Methods from Deref<Target = AnyObject>§
Sourcepub fn class(&self) -> &'static AnyClass
pub fn class(&self) -> &'static AnyClass
Dynamically find the class of this object.
§Panics
May panic if the object is invalid (which may be the case for objects
returned from unavailable init/new methods).
§Example
Check that an instance of NSObject has the precise class NSObject.
use objc2::ClassType;
use objc2::runtime::NSObject;
let obj = NSObject::new();
assert_eq!(obj.class(), NSObject::class());Sourcepub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
👎Deprecated: this is difficult to use correctly, use Ivar::load instead.
pub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
this is difficult to use correctly, use Ivar::load instead.
Use Ivar::load instead.
§Safety
The object must have an instance variable with the given name, and it
must be of type T.
See Ivar::load_ptr for details surrounding this.
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
Attempt to downcast the object to a class of type T.
This is the reference-variant. Use Retained::downcast if you want
to convert a retained object to another type.
§Mutable classes
Some classes have immutable and mutable variants, such as NSString
and NSMutableString.
When some Objective-C API signature says it gives you an immutable class, it generally expects you to not mutate that, even though it may technically be mutable “under the hood”.
So using this method to convert a NSString to a NSMutableString,
while not unsound, is generally frowned upon unless you created the
string yourself, or the API explicitly documents the string to be
mutable.
See Apple’s documentation on mutability and on
isKindOfClass: for more details.
§Generic classes
Objective-C generics are called “lightweight generics”, and that’s because they aren’t exposed in the runtime. This makes it impossible to safely downcast to generic collections, so this is disallowed by this method.
You can, however, safely downcast to generic collections where all the
type-parameters are AnyObject.
§Panics
This works internally by calling isKindOfClass:. That means that the
object must have the instance method of that name, and an exception
will be thrown (if CoreFoundation is linked) or the process will abort
if that is not the case. In the vast majority of cases, you don’t need
to worry about this, since both root objects NSObject and
NSProxy implement this method.
§Examples
Cast an NSString back and forth from NSObject.
use objc2::rc::Retained;
use objc2_foundation::{NSObject, NSString};
let obj: Retained<NSObject> = NSString::new().into_super();
let string = obj.downcast_ref::<NSString>().unwrap();
// Or with `downcast`, if we do not need the object afterwards
let string = obj.downcast::<NSString>().unwrap();Try (and fail) to cast an NSObject to an NSString.
use objc2_foundation::{NSObject, NSString};
let obj = NSObject::new();
assert!(obj.downcast_ref::<NSString>().is_none());Try to cast to an array of strings.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
// This is invalid and doesn't type check.
let arr = arr.downcast_ref::<NSArray<NSString>>();This fails to compile, since it would require enumerating over the array to ensure that each element is of the desired type, which is a performance pitfall.
Downcast when processing each element instead.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
for elem in arr {
if let Some(data) = elem.downcast_ref::<NSString>() {
// handle `data`
}
}Trait Implementations§
Source§impl AsRef<AnyObject> for AppDelegate
impl AsRef<AnyObject> for AppDelegate
Source§impl AsRef<AppDelegate> for AppDelegate
impl AsRef<AppDelegate> for AppDelegate
Source§impl AsRef<NSObject> for AppDelegate
impl AsRef<NSObject> for AppDelegate
Source§impl Borrow<AnyObject> for AppDelegate
impl Borrow<AnyObject> for AppDelegate
Source§impl Borrow<NSObject> for AppDelegate
impl Borrow<NSObject> for AppDelegate
Source§impl ClassType for AppDelegate
impl ClassType for AppDelegate
Source§const NAME: &'static str = "NiftyAppDelegate"
const NAME: &'static str = "NiftyAppDelegate"
Source§type ThreadKind = dyn MainThreadOnly
type ThreadKind = dyn MainThreadOnly
Source§impl Debug for AppDelegate
impl Debug for AppDelegate
Source§impl DefinedClass for AppDelegate
impl DefinedClass for AppDelegate
Source§impl Deref for AppDelegate
impl Deref for AppDelegate
impl DowncastTarget for AppDelegate
Source§impl Message for AppDelegate
impl Message for AppDelegate
Source§impl NSApplicationDelegate for AppDelegate
impl NSApplicationDelegate for AppDelegate
Source§fn applicationShouldTerminate(
&self,
sender: &NSApplication,
) -> NSApplicationTerminateReply
fn applicationShouldTerminate( &self, sender: &NSApplication, ) -> NSApplicationTerminateReply
NSTerminateNow- it is ok to proceed with termination
NSTerminateCancel- the application should not be terminated
NSTerminateLater- it may be ok to proceed with termination later. The application must call -replyToApplicationShouldTerminate: with
YESor
NOonce the answer is known Read moreSource§fn application_openURLs(
&self,
application: &NSApplication,
urls: &NSArray<NSURL>,
)
fn application_openURLs( &self, application: &NSApplication, urls: &NSArray<NSURL>, )
CFBundleDocumentTypes)that have no associated
NSDocumentclass. Document URLs that have an associated
NSDocumentclass will be opened through
NSDocumentController.If this is implemented, -application:openFiles: and -application:openFile: will not be called.fn application_openFile( &self, sender: &NSApplication, filename: &NSString, ) -> bool
fn application_openFiles( &self, sender: &NSApplication, filenames: &NSArray<NSString>, )
fn application_openTempFile( &self, sender: &NSApplication, filename: &NSString, ) -> bool
fn applicationShouldOpenUntitledFile(&self, sender: &NSApplication) -> bool
fn applicationOpenUntitledFile(&self, sender: &NSApplication) -> bool
Source§unsafe fn application_openFileWithoutUI(
&self,
sender: &AnyObject,
filename: &NSString,
) -> bool
unsafe fn application_openFileWithoutUI( &self, sender: &AnyObject, filename: &NSString, ) -> bool
fn application_printFile( &self, sender: &NSApplication, filename: &NSString, ) -> bool
Source§unsafe fn application_printFiles_withSettings_showPrintPanels(
&self,
application: &NSApplication,
file_names: &NSArray<NSString>,
print_settings: &NSDictionary<NSString>,
show_print_panels: bool,
) -> NSApplicationPrintReply
unsafe fn application_printFiles_withSettings_showPrintPanels( &self, application: &NSApplication, file_names: &NSArray<NSString>, print_settings: &NSDictionary<NSString>, show_print_panels: bool, ) -> NSApplicationPrintReply
fn applicationShouldTerminateAfterLastWindowClosed( &self, sender: &NSApplication, ) -> bool
fn applicationShouldHandleReopen_hasVisibleWindows( &self, sender: &NSApplication, has_visible_windows: bool, ) -> bool
fn applicationDockMenu( &self, sender: &NSApplication, ) -> Option<Retained<NSMenu>>
fn application_willPresentError( &self, application: &NSApplication, error: &NSError, ) -> Retained<NSError> ⓘ
fn application_didRegisterForRemoteNotificationsWithDeviceToken( &self, application: &NSApplication, device_token: &NSData, )
fn application_didFailToRegisterForRemoteNotificationsWithError( &self, application: &NSApplication, error: &NSError, )
Source§unsafe fn application_didReceiveRemoteNotification(
&self,
application: &NSApplication,
user_info: &NSDictionary<NSString>,
)
unsafe fn application_didReceiveRemoteNotification( &self, application: &NSApplication, user_info: &NSDictionary<NSString>, )
Source§fn applicationSupportsSecureRestorableState(&self, app: &NSApplication) -> bool
fn applicationSupportsSecureRestorableState(&self, app: &NSApplication) -> bool
Source§unsafe fn application_willEncodeRestorableState(
&self,
app: &NSApplication,
coder: &NSCoder,
)
unsafe fn application_willEncodeRestorableState( &self, app: &NSApplication, coder: &NSCoder, )
-[NSApplication encodeRestorableStateWithCoder:] to give the delegate a chance to encode any additional state into the
NSCoder.If the restorable state managed by the delegate changes, you must call -[NSApplication invalidateRestorableState] so that it will be re-encoded. See the header NSWindowRestoration.h for more information. Read moreSource§unsafe fn application_didDecodeRestorableState(
&self,
app: &NSApplication,
coder: &NSCoder,
)
unsafe fn application_didDecodeRestorableState( &self, app: &NSApplication, coder: &NSCoder, )
-[NSApplication restoreStateWithCoder:] to give the delegate a chance to restore its own state, which it may decode from the
NSCoder.See the header NSWindowRestoration.h for more information. Read moreSource§fn application_willContinueUserActivityWithType(
&self,
application: &NSApplication,
user_activity_type: &NSString,
) -> bool
fn application_willContinueUserActivityWithType( &self, application: &NSApplication, user_activity_type: &NSString, ) -> bool
NSUserActivityobject may not be available instantly, so use this as an opportunity to show the user that an activity will be continued shortly. Return
YESto indicate that you are doing so. Return
NO(or leave it unimplemented) and AppKit/UIKit will put up a default UI. Read moreSource§fn application_continueUserActivity_restorationHandler(
&self,
application: &NSApplication,
user_activity: &NSUserActivity,
restoration_handler: &Block<dyn Fn(NonNull<NSArray<ProtocolObject<dyn NSUserActivityRestoring>>>)>,
) -> bool
fn application_continueUserActivity_restorationHandler( &self, application: &NSApplication, user_activity: &NSUserActivity, restoration_handler: &Block<dyn Fn(NonNull<NSArray<ProtocolObject<dyn NSUserActivityRestoring>>>)>, ) -> bool
NSUserActivityobject is available. Use the data you stored in the NSUserActivity object to re-create what the user was doing. Read moreSource§fn application_didFailToContinueUserActivityWithType_error(
&self,
application: &NSApplication,
user_activity_type: &NSString,
error: &NSError,
)
fn application_didFailToContinueUserActivityWithType_error( &self, application: &NSApplication, user_activity_type: &NSString, error: &NSError, )
NSUserActivitymay fail. This will get called on the main thread if it does so. If it is unimplemented, AppKit will present the error.Source§fn application_didUpdateUserActivity(
&self,
application: &NSApplication,
user_activity: &NSUserActivity,
)
fn application_didUpdateUserActivity( &self, application: &NSApplication, user_activity: &NSUserActivity, )
userActivity.Source§fn application_delegateHandlesKey(
&self,
sender: &NSApplication,
key: &NSString,
) -> bool
fn application_delegateHandlesKey( &self, sender: &NSApplication, key: &NSString, ) -> bool
YESif the receiving delegate object can respond to key value coding messages for a specific keyed attribute, to-one relationship, or to-many relationship. Return
NOotherwise.Source§fn applicationShouldAutomaticallyLocalizeKeyEquivalents(
&self,
application: &NSApplication,
) -> bool
fn applicationShouldAutomaticallyLocalizeKeyEquivalents( &self, application: &NSApplication, ) -> bool
-[NSApplication finishLaunching]. Read morefn applicationWillFinishLaunching(&self, notification: &NSNotification)
fn applicationDidFinishLaunching(&self, notification: &NSNotification)
fn applicationWillHide(&self, notification: &NSNotification)
fn applicationDidHide(&self, notification: &NSNotification)
fn applicationWillUnhide(&self, notification: &NSNotification)
fn applicationDidUnhide(&self, notification: &NSNotification)
fn applicationWillBecomeActive(&self, notification: &NSNotification)
fn applicationDidBecomeActive(&self, notification: &NSNotification)
fn applicationWillResignActive(&self, notification: &NSNotification)
fn applicationDidResignActive(&self, notification: &NSNotification)
fn applicationWillUpdate(&self, notification: &NSNotification)
fn applicationDidUpdate(&self, notification: &NSNotification)
fn applicationWillTerminate(&self, notification: &NSNotification)
fn applicationDidChangeScreenParameters(&self, notification: &NSNotification)
fn applicationDidChangeOcclusionState(&self, notification: &NSNotification)
fn applicationProtectedDataDidBecomeAvailable( &self, notification: &NSNotification, )
Source§impl NSObjectProtocol for AppDelegate
impl NSObjectProtocol for AppDelegate
Source§fn isEqual(&self, other: Option<&AnyObject>) -> bool
fn isEqual(&self, other: Option<&AnyObject>) -> bool
Source§fn hash(&self) -> usize
fn hash(&self) -> usize
Source§fn isKindOfClass(&self, cls: &AnyClass) -> bool
fn isKindOfClass(&self, cls: &AnyClass) -> bool
Source§fn is_kind_of<T>(&self) -> bool
fn is_kind_of<T>(&self) -> bool
use isKindOfClass directly, or cast your objects with AnyObject::downcast_ref
Source§fn isMemberOfClass(&self, cls: &AnyClass) -> bool
fn isMemberOfClass(&self, cls: &AnyClass) -> bool
Source§fn respondsToSelector(&self, aSelector: Sel) -> bool
fn respondsToSelector(&self, aSelector: Sel) -> bool
Source§fn conformsToProtocol(&self, aProtocol: &AnyProtocol) -> bool
fn conformsToProtocol(&self, aProtocol: &AnyProtocol) -> bool
Source§fn description(&self) -> Retained<NSObject> ⓘ
fn description(&self) -> Retained<NSObject> ⓘ
Source§fn debugDescription(&self) -> Retained<NSObject> ⓘ
fn debugDescription(&self) -> Retained<NSObject> ⓘ
Source§impl RefEncode for AppDelegate
impl RefEncode for AppDelegate
Source§const ENCODING_REF: Encoding = <NSObject as ::objc2::RefEncode>::ENCODING_REF
const ENCODING_REF: Encoding = <NSObject as ::objc2::RefEncode>::ENCODING_REF
Auto Trait Implementations§
impl !Freeze for AppDelegate
impl !Send for AppDelegate
impl !Sync for AppDelegate
impl !Unpin for AppDelegate
impl RefUnwindSafe for AppDelegate
impl UnsafeUnpin for AppDelegate
impl UnwindSafe for AppDelegate
Blanket Implementations§
impl<T> AutoreleaseSafe for Twhere
T: ?Sized,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<'a, T> MainThreadOnly for T
impl<'a, T> MainThreadOnly for T
Source§fn mtm(&self) -> MainThreadMarker
fn mtm(&self) -> MainThreadMarker
MainThreadMarker from the main-thread-only object. Read more