#[repr(C)]pub struct EKEventStore { /* private fields */ }
EKEventStore
only.Expand description
The EKEventStore class provides an interface for accessing and manipulating calendar events and reminders.
The EKEventStore class is the main point of contact for accessing Calendar data. You must create a EKEventStore object in order to retrieve/add/delete events or reminders from the Calendar database.
Events, Reminders, and Calendar objects retrieved from an event store cannot be used with any other event store. It is generally best to hold onto a long-lived instance of an event store, most likely as a singleton instance in your application.
See also Apple’s documentation
Implementations§
Source§impl EKEventStore
impl EKEventStore
Available on crate feature EKTypes
only.
EKTypes
only.Returns the authorization status for the given entity type
Sourcepub unsafe fn initWithAccessToEntityTypes(
this: Allocated<Self>,
entity_types: EKEntityMask,
) -> Retained<Self>
👎DeprecatedAvailable on crate feature EKTypes
only.
pub unsafe fn initWithAccessToEntityTypes( this: Allocated<Self>, entity_types: EKEntityMask, ) -> Retained<Self>
EKTypes
only.Users are able to grant or deny access to event and reminder data on a per-app basis. To request access to event and/or reminder data, instantiate an EKEventStore using this method. This call will not block the program while the user is being asked to grant or deny access. Until access has been granted for an entity type, this event store will not contain any calendars for that entity type, and any attempt to save entities of that entity type will fail. If access is later granted or declined, the event store will broadcast an EKEventStoreChangedNotification. You can check the current access status for an entity type using +authorizationStatusForEntityType:. The user will only be prompted the first time access is requested; any subsequent instantiations of EKEventStore will use the existing permissions.
Parameter entityTypes
: A bit mask of entity types to which you want access
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>
Sourcepub unsafe fn initWithSources(
this: Allocated<Self>,
sources: &NSArray<EKSource>,
) -> Retained<Self>
Available on crate features EKObject
and EKSource
only.
pub unsafe fn initWithSources( this: Allocated<Self>, sources: &NSArray<EKSource>, ) -> Retained<Self>
EKObject
and EKSource
only.Creates a new event store that only includes items and calendars for a subset of sources.
Parameter sources
: The sources you want this event store to recognize. This may include delegate sources.
pub unsafe fn requestFullAccessToEventsWithCompletion( &self, completion: EKEventStoreRequestAccessCompletionHandler, )
block2
only.pub unsafe fn requestWriteOnlyAccessToEventsWithCompletion( &self, completion: EKEventStoreRequestAccessCompletionHandler, )
block2
only.pub unsafe fn requestFullAccessToRemindersWithCompletion( &self, completion: EKEventStoreRequestAccessCompletionHandler, )
block2
only.pub unsafe fn requestAccessToEntityType_completion( &self, entity_type: EKEntityType, completion: EKEventStoreRequestAccessCompletionHandler, )
EKTypes
and block2
only.Sourcepub unsafe fn eventStoreIdentifier(&self) -> Retained<NSString>
pub unsafe fn eventStoreIdentifier(&self) -> Retained<NSString>
Returns a unique identifier string representing this calendar store.
Sourcepub unsafe fn delegateSources(&self) -> Retained<NSArray<EKSource>>
Available on crate features EKObject
and EKSource
only.
pub unsafe fn delegateSources(&self) -> Retained<NSArray<EKSource>>
EKObject
and EKSource
only.Returns an unordered array of sources for all available delegates.
Sourcepub unsafe fn sources(&self) -> Retained<NSArray<EKSource>>
Available on crate features EKObject
and EKSource
only.
pub unsafe fn sources(&self) -> Retained<NSArray<EKSource>>
EKObject
and EKSource
only.Returns an unordered array of sources.
Sourcepub unsafe fn sourceWithIdentifier(
&self,
identifier: &NSString,
) -> Option<Retained<EKSource>>
Available on crate features EKObject
and EKSource
only.
pub unsafe fn sourceWithIdentifier( &self, identifier: &NSString, ) -> Option<Retained<EKSource>>
EKObject
and EKSource
only.Returns a source with a specified identifier.
Sourcepub unsafe fn calendars(&self) -> Retained<NSArray<EKCalendar>>
Available on crate features EKCalendar
and EKObject
only.
pub unsafe fn calendars(&self) -> Retained<NSArray<EKCalendar>>
EKCalendar
and EKObject
only.While this returns an array, the calendars are unordered. This call is deprecated and only returns calendars that support events. If you want reminder calendars you should use calendarsForEntityType:
Sourcepub unsafe fn calendarsForEntityType(
&self,
entity_type: EKEntityType,
) -> Retained<NSArray<EKCalendar>>
Available on crate features EKCalendar
and EKObject
and EKTypes
only.
pub unsafe fn calendarsForEntityType( &self, entity_type: EKEntityType, ) -> Retained<NSArray<EKCalendar>>
EKCalendar
and EKObject
and EKTypes
only.Returns calendars that support a given entity type (reminders, events)
Sourcepub unsafe fn defaultCalendarForNewEvents(&self) -> Option<Retained<EKCalendar>>
Available on crate features EKCalendar
and EKObject
only.
pub unsafe fn defaultCalendarForNewEvents(&self) -> Option<Retained<EKCalendar>>
EKCalendar
and EKObject
only.Returns the calendar that events should be added to by default.
This may be nil if there is no default calendar for new events.
Sourcepub unsafe fn defaultCalendarForNewReminders(
&self,
) -> Option<Retained<EKCalendar>>
Available on crate features EKCalendar
and EKObject
only.
pub unsafe fn defaultCalendarForNewReminders( &self, ) -> Option<Retained<EKCalendar>>
EKCalendar
and EKObject
only.Returns the calendar that reminders should be added to by default.
This may be nil if there is no default calendar for new reminders.
Sourcepub unsafe fn calendarWithIdentifier(
&self,
identifier: &NSString,
) -> Option<Retained<EKCalendar>>
Available on crate features EKCalendar
and EKObject
only.
pub unsafe fn calendarWithIdentifier( &self, identifier: &NSString, ) -> Option<Retained<EKCalendar>>
EKCalendar
and EKObject
only.Returns a calendar with a specified identifier.
Sourcepub unsafe fn saveCalendar_commit_error(
&self,
calendar: &EKCalendar,
commit: bool,
) -> Result<(), Retained<NSError>>
Available on crate features EKCalendar
and EKObject
only.
pub unsafe fn saveCalendar_commit_error( &self, calendar: &EKCalendar, commit: bool, ) -> Result<(), Retained<NSError>>
EKCalendar
and EKObject
only.Saves changes to a calendar, or adds a new calendar to the database.
This method attempts to save the given calendar to the calendar database. It returns YES if successful and NO otherwise. Passing a calendar fetched from another EKEventStore instance into this function will raise an exception. On WatchOS, saving changes is not supported.
Parameter calendar
: The calendar to save.
Parameter commit
: Pass YES to cause the database to save. You can pass NO to save multiple
calendars and then call commit: to save them all at once.
Parameter error
: If an error occurs, this will contain a valid NSError object on exit.
Sourcepub unsafe fn removeCalendar_commit_error(
&self,
calendar: &EKCalendar,
commit: bool,
) -> Result<(), Retained<NSError>>
Available on crate features EKCalendar
and EKObject
only.
pub unsafe fn removeCalendar_commit_error( &self, calendar: &EKCalendar, commit: bool, ) -> Result<(), Retained<NSError>>
EKCalendar
and EKObject
only.Removes a calendar from the database.
This method attempts to delete the given calendar from the calendar database. It returns YES if successful and NO otherwise. Passing a calendar fetched from another EKEventStore instance into this function will raise an exception.
If the calendar supports multiple entity types (allowedEntityTypes), but the user has not granted you access to all those entity types, then we will delete all of the entity types for which you have access and remove that entity type from the allowedEntityTypes. For example: If a calendar supports both events and reminders, but you only have access to reminders, we will delete all the reminders and make the calendar only support events.
If you have access to all of its allowedEntityTypes, then it will delete the calendar and all of the events and reminders in the calendar.
On WatchOS, modifying the database is not supported.
Parameter calendar
: The calendar to delete.
Parameter commit
: Pass YES to cause the database to save. You can pass NO to batch multiple
changes and then call commit: to save them all at once.
Parameter error
: If an error occurs, this will contain a valid NSError object on exit.
Sourcepub unsafe fn calendarItemWithIdentifier(
&self,
identifier: &NSString,
) -> Option<Retained<EKCalendarItem>>
Available on crate features EKCalendarItem
and EKObject
only.
pub unsafe fn calendarItemWithIdentifier( &self, identifier: &NSString, ) -> Option<Retained<EKCalendarItem>>
EKCalendarItem
and EKObject
only.Returns either a reminder or the first occurrence of an event.
Sourcepub unsafe fn calendarItemsWithExternalIdentifier(
&self,
external_identifier: &NSString,
) -> Retained<NSArray<EKCalendarItem>>
Available on crate features EKCalendarItem
and EKObject
only.
pub unsafe fn calendarItemsWithExternalIdentifier( &self, external_identifier: &NSString, ) -> Retained<NSArray<EKCalendarItem>>
EKCalendarItem
and EKObject
only.Returns either matching reminders or the first occurrences of any events matching the given external identifier.
This method returns a set of EKEvents or EKReminders with the given external identifier. Due to reasons discussed in -[EKCalendarItem calendarItemExternalIdentifier], there may be more than one matching calendar item.
Parameter externalIdentifier
: The value obtained from EKCalendarItem’s
calendarItemExternalIdentifier property
Returns: An unsorted array of EKCalendarItem instances
Sourcepub unsafe fn saveEvent_span_error(
&self,
event: &EKEvent,
span: EKSpan,
) -> Result<(), Retained<NSError>>
Available on crate features EKCalendarItem
and EKEvent
and EKObject
only.
pub unsafe fn saveEvent_span_error( &self, event: &EKEvent, span: EKSpan, ) -> Result<(), Retained<NSError>>
EKCalendarItem
and EKEvent
and EKObject
only.Saves changes to an event permanently.
This method attempts to save the event to the calendar database. It returns YES if successful and NO otherwise. It’s possible for this method to return NO, and error will be set to nil. This occurs if the event wasn’t dirty and didn’t need saving. This means the correct way to detect failure is a result of NO and a non-nil error parameter. Passing an event fetched from another EKEventStore instance into this function will raise an exception.
After an event is successfully saved, it is also put into sync with the database, meaning that all fields you did not change will be updated to the latest values. If you save the event, but it was deleted by a different store/process, you will effectively recreate the event as a new event.
On WatchOS, saving changes is not supported.
Parameter event
: The event to save.
Parameter span
: The span to use (this event, or this and future events).
Parameter error
: If an error occurs, this will contain a valid NSError object on exit.
Sourcepub unsafe fn removeEvent_span_error(
&self,
event: &EKEvent,
span: EKSpan,
) -> Result<(), Retained<NSError>>
Available on crate features EKCalendarItem
and EKEvent
and EKObject
only.
pub unsafe fn removeEvent_span_error( &self, event: &EKEvent, span: EKSpan, ) -> Result<(), Retained<NSError>>
EKCalendarItem
and EKEvent
and EKObject
only.Removes an event from the calendar store.
This method attempts to remove the event from the calendar database. It returns YES if successful and NO otherwise. It’s possible for this method to return NO, and error will be set to nil. This occurs if the event wasn’t ever added and didn’t need removing. This means the correct way to detect failure is a result of NO and a non-nil error parameter. Passing an event from another CalendarStore into this function will raise an exception. After an event is removed, it is no longer tied to this calendar store, and all data in the event is cleared except for the eventIdentifier.
On WatchOS, modifying the database is not supported.
Parameter event
: The event to save.
Parameter span
: The span to use (this event, or this and future events).
Parameter error
: If an error occurs, this will contain a valid NSError object on exit.
pub unsafe fn saveEvent_span_commit_error( &self, event: &EKEvent, span: EKSpan, commit: bool, ) -> Result<(), Retained<NSError>>
EKCalendarItem
and EKEvent
and EKObject
only.pub unsafe fn removeEvent_span_commit_error( &self, event: &EKEvent, span: EKSpan, commit: bool, ) -> Result<(), Retained<NSError>>
EKCalendarItem
and EKEvent
and EKObject
only.Sourcepub unsafe fn eventWithIdentifier(
&self,
identifier: &NSString,
) -> Option<Retained<EKEvent>>
Available on crate features EKCalendarItem
and EKEvent
and EKObject
only.
pub unsafe fn eventWithIdentifier( &self, identifier: &NSString, ) -> Option<Retained<EKEvent>>
EKCalendarItem
and EKEvent
and EKObject
only.Returns the first occurrence of an event matching the given event identifier.
Parameter identifier
: The eventIdentifier to search for.
Returns: An EKEvent object, or nil if not found.
Sourcepub unsafe fn eventsMatchingPredicate(
&self,
predicate: &NSPredicate,
) -> Retained<NSArray<EKEvent>>
Available on crate features EKCalendarItem
and EKEvent
and EKObject
only.
pub unsafe fn eventsMatchingPredicate( &self, predicate: &NSPredicate, ) -> Retained<NSArray<EKEvent>>
EKCalendarItem
and EKEvent
and EKObject
only.Searches for events that match the given predicate.
This call executes a search for the events indicated by the predicate passed to it.
It is synchronous. If you want async behavior, you should either use dispatch_async or NSOperation to run the query someplace other than the main thread, and then funnel the array back to the main thread.
Parameter predicate
: The predicate to invoke. If this predicate was not created with the predicate
creation functions in this class, an exception is raised.
Returns: An array of EKEvent objects, or nil. There is no guaranteed order to the events.
Sourcepub unsafe fn enumerateEventsMatchingPredicate_usingBlock(
&self,
predicate: &NSPredicate,
block: EKEventSearchCallback,
)
Available on crate features EKCalendarItem
and EKEvent
and EKObject
and block2
only.
pub unsafe fn enumerateEventsMatchingPredicate_usingBlock( &self, predicate: &NSPredicate, block: EKEventSearchCallback, )
EKCalendarItem
and EKEvent
and EKObject
and block2
only.Searches for events that match the given predicate.
This call executes a search for the events indicated by the predicate passed to it, calling the block specified in the callback parameter for each event.
This method is synchronous. If you want async behavior, you should either use dispatch_async or NSOperation to run the query someplace other than the main thread.
Parameter predicate
: The predicate to invoke. If this predicate was not created with the predicate
creation functions in this class, an exception is raised.
Parameter block
: The block to call for each event. Your block should return YES in the stop
parameter to stop iterating.
Sourcepub unsafe fn predicateForEventsWithStartDate_endDate_calendars(
&self,
start_date: &NSDate,
end_date: &NSDate,
calendars: Option<&NSArray<EKCalendar>>,
) -> Retained<NSPredicate>
Available on crate features EKCalendar
and EKObject
only.
pub unsafe fn predicateForEventsWithStartDate_endDate_calendars( &self, start_date: &NSDate, end_date: &NSDate, calendars: Option<&NSArray<EKCalendar>>, ) -> Retained<NSPredicate>
EKCalendar
and EKObject
only.Creates a predicate for use with eventsMatchingPredicate or enumerateEventsMatchingPredicate:usingBlock:.
Creates a simple query predicate to search for events within a certain date range. At present, this will return events in the default time zone ([NSTimeZone defaultTimeZone]).
For performance reasons, this method will only return events within a four year timespan. If the date range between the startDate and endDate is greater than four years, then it will be shortened to the first four years.
Parameter startDate
: The start date.
Parameter endDate
: The end date.
Parameter calendars
: The calendars to search for events in, or nil to search all calendars.
Sourcepub unsafe fn saveReminder_commit_error(
&self,
reminder: &EKReminder,
commit: bool,
) -> Result<(), Retained<NSError>>
Available on crate features EKCalendarItem
and EKObject
and EKReminder
only.
pub unsafe fn saveReminder_commit_error( &self, reminder: &EKReminder, commit: bool, ) -> Result<(), Retained<NSError>>
EKCalendarItem
and EKObject
and EKReminder
only.Saves changes to a reminder.
This method attempts to save the reminder to the event store database. It returns YES if successful and NO otherwise. Passing a reminder fetched from another EKEventStore instance into this function will raise an exception.
After a reminder is successfully saved, its fields are updated to the latest values in the database.
On WatchOS, saving changes is not supported.
Parameter reminder
: The reminder to save.
Parameter commit
: Whether to save to the database or not. Pass NO to batch changes together and
commit with [EKEventStore commit:].
Parameter error
: If an error occurs, this will contain a valid NSError object on exit.
Sourcepub unsafe fn removeReminder_commit_error(
&self,
reminder: &EKReminder,
commit: bool,
) -> Result<(), Retained<NSError>>
Available on crate features EKCalendarItem
and EKObject
and EKReminder
only.
pub unsafe fn removeReminder_commit_error( &self, reminder: &EKReminder, commit: bool, ) -> Result<(), Retained<NSError>>
EKCalendarItem
and EKObject
and EKReminder
only.Removes a reminder from the event store.
This method attempts to remove the reminder from the event store database. It returns YES if successful and NO otherwise. Passing a reminder from another EKEventStore into this function will raise an exception. After a reminder is removed, it is no longer tied to this event store.
On WatchOS, modifying the database is not supported.
Parameter reminder
: The reminder to save.
Parameter commit
: Whether to save to the database or not. Pass NO to batch changes together and
commit with [EKEventStore commit:].
Parameter error
: If an error occurs, this will contain a valid NSError object on exit.
Sourcepub unsafe fn fetchRemindersMatchingPredicate_completion(
&self,
predicate: &NSPredicate,
completion: &DynBlock<dyn Fn(*mut NSArray<EKReminder>)>,
) -> Retained<AnyObject>
Available on crate features EKCalendarItem
and EKObject
and EKReminder
and block2
only.
pub unsafe fn fetchRemindersMatchingPredicate_completion( &self, predicate: &NSPredicate, completion: &DynBlock<dyn Fn(*mut NSArray<EKReminder>)>, ) -> Retained<AnyObject>
EKCalendarItem
and EKObject
and EKReminder
and block2
only.Fetches reminders asynchronously.
This method fetches reminders asynchronously and returns a value which can be used in cancelFetchRequest: to cancel the request later if desired. The completion block is called with an array of reminders that match the given predicate (or potentially nil).
Sourcepub unsafe fn cancelFetchRequest(&self, fetch_identifier: &AnyObject)
pub unsafe fn cancelFetchRequest(&self, fetch_identifier: &AnyObject)
Given a value returned from fetchRemindersMatchingPredicate, this method can be used to cancel the request. Once called, the completion block specified in fetchReminders… will not be called.
Sourcepub unsafe fn predicateForRemindersInCalendars(
&self,
calendars: Option<&NSArray<EKCalendar>>,
) -> Retained<NSPredicate>
Available on crate features EKCalendar
and EKObject
only.
pub unsafe fn predicateForRemindersInCalendars( &self, calendars: Option<&NSArray<EKCalendar>>, ) -> Retained<NSPredicate>
EKCalendar
and EKObject
only.Fetch all reminders in a set of calendars.
You can pass nil for calendars to fetch from all available calendars.
Sourcepub unsafe fn predicateForIncompleteRemindersWithDueDateStarting_ending_calendars(
&self,
start_date: Option<&NSDate>,
end_date: Option<&NSDate>,
calendars: Option<&NSArray<EKCalendar>>,
) -> Retained<NSPredicate>
Available on crate features EKCalendar
and EKObject
only.
pub unsafe fn predicateForIncompleteRemindersWithDueDateStarting_ending_calendars( &self, start_date: Option<&NSDate>, end_date: Option<&NSDate>, calendars: Option<&NSArray<EKCalendar>>, ) -> Retained<NSPredicate>
EKCalendar
and EKObject
only.Fetch incomplete reminders in a set of calendars.
You can use this method to search for incomplete reminders due in a range. You can pass nil for start date to find all reminders due before endDate. You can pass nil for both start and end date to get all incomplete reminders in the specified calendars. You can pass nil for calendars to fetch from all available calendars.
Sourcepub unsafe fn predicateForCompletedRemindersWithCompletionDateStarting_ending_calendars(
&self,
start_date: Option<&NSDate>,
end_date: Option<&NSDate>,
calendars: Option<&NSArray<EKCalendar>>,
) -> Retained<NSPredicate>
Available on crate features EKCalendar
and EKObject
only.
pub unsafe fn predicateForCompletedRemindersWithCompletionDateStarting_ending_calendars( &self, start_date: Option<&NSDate>, end_date: Option<&NSDate>, calendars: Option<&NSArray<EKCalendar>>, ) -> Retained<NSPredicate>
EKCalendar
and EKObject
only.Fetch completed reminders in a set of calendars.
You can use this method to search for reminders completed between a range of dates. You can pass nil for start date to find all reminders completed before endDate. You can pass nil for both start and end date to get all completed reminders in the specified calendars. You can pass nil for calendars to fetch from all available calendars.
Sourcepub unsafe fn commit(&self) -> Result<(), Retained<NSError>>
pub unsafe fn commit(&self) -> Result<(), Retained<NSError>>
Commits pending changes to the database.
If you use saveCalendar/saveEvent/removeCalendar/removeEvent, etc. and you pass NO to their parameter, you are batching changes for a later commit. This method does that commit. This allows you to save the database only once for many additions or changes. If you pass YES to methods’ commit parameter, then you don’t need to call this method.
This method will return YES as long as nothing went awry, even if nothing was actually committed. If it returns NO, error should contain the reason it became unhappy.
On WatchOS, modifying the database is not supported.
Sourcepub unsafe fn reset(&self)
pub unsafe fn reset(&self)
Resets the event store.
You can use this method to forget ALL changes made to the event store (all additions, all fetched objects, etc.). It essentially is as if you released the store and then created a new one. It brings it back to its initial state. All objects ever created/fetched, etc. using this store are no longer connected to it and are considered invalid.
Sourcepub unsafe fn refreshSourcesIfNecessary(&self)
pub unsafe fn refreshSourcesIfNecessary(&self)
Cause a sync to potentially occur taking into account the necessity of it.
You can call this method to pull new data from remote sources. This only updates the event store’s data. If you want to update your objects after refreshing the sources, you should call refresh on each of them afterwards. On iOS and macOS, this sync only occurs if deemed necessary. On WatchOS, initiating sync is not available. Sync will occur automatically with the paired iOS device.
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,
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 EKEventStore
impl AsRef<AnyObject> for EKEventStore
Source§impl AsRef<EKEventStore> for EKEventStore
impl AsRef<EKEventStore> for EKEventStore
Source§impl AsRef<NSObject> for EKEventStore
impl AsRef<NSObject> for EKEventStore
Source§impl Borrow<AnyObject> for EKEventStore
impl Borrow<AnyObject> for EKEventStore
Source§impl Borrow<NSObject> for EKEventStore
impl Borrow<NSObject> for EKEventStore
Source§impl ClassType for EKEventStore
impl ClassType for EKEventStore
Source§const NAME: &'static str = "EKEventStore"
const NAME: &'static str = "EKEventStore"
Source§type ThreadKind = <<EKEventStore as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<EKEventStore as ClassType>::Super as ClassType>::ThreadKind
Source§impl Debug for EKEventStore
impl Debug for EKEventStore
Source§impl Deref for EKEventStore
impl Deref for EKEventStore
Source§impl Hash for EKEventStore
impl Hash for EKEventStore
Source§impl Message for EKEventStore
impl Message for EKEventStore
Source§impl NSObjectProtocol for EKEventStore
impl NSObjectProtocol for EKEventStore
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
isKindOfClass
directly, or cast your objects with AnyObject::downcast_ref