pub struct NSCalendar { /* private fields */ }
NSCalendar
only.Expand description
Implementations§
Source§impl NSCalendar
impl NSCalendar
pub fn currentCalendar() -> Retained<NSCalendar>
pub fn autoupdatingCurrentCalendar() -> Retained<NSCalendar>
pub fn calendarWithIdentifier( calendar_identifier_constant: &NSCalendarIdentifier, ) -> Option<Retained<NSCalendar>>
NSString
only.pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>
pub fn initWithCalendarIdentifier( this: Allocated<Self>, ident: &NSCalendarIdentifier, ) -> Option<Retained<Self>>
NSString
only.pub fn calendarIdentifier(&self) -> Retained<NSCalendarIdentifier>
NSString
only.pub fn locale(&self) -> Option<Retained<NSLocale>>
NSLocale
only.pub fn timeZone(&self) -> Retained<NSTimeZone>
NSTimeZone
only.Sourcepub fn setTimeZone(&self, time_zone: &NSTimeZone)
Available on crate feature NSTimeZone
only.
pub fn setTimeZone(&self, time_zone: &NSTimeZone)
NSTimeZone
only.pub fn firstWeekday(&self) -> NSUInteger
Sourcepub fn setFirstWeekday(&self, first_weekday: NSUInteger)
pub fn setFirstWeekday(&self, first_weekday: NSUInteger)
Setter for firstWeekday
.
pub fn minimumDaysInFirstWeek(&self) -> NSUInteger
Sourcepub fn setMinimumDaysInFirstWeek(&self, minimum_days_in_first_week: NSUInteger)
pub fn setMinimumDaysInFirstWeek(&self, minimum_days_in_first_week: NSUInteger)
Setter for minimumDaysInFirstWeek
.
pub fn eraSymbols(&self) -> Retained<NSArray<NSString>>
NSArray
and NSString
only.pub fn longEraSymbols(&self) -> Retained<NSArray<NSString>>
NSArray
and NSString
only.pub fn monthSymbols(&self) -> Retained<NSArray<NSString>>
NSArray
and NSString
only.pub fn shortMonthSymbols(&self) -> Retained<NSArray<NSString>>
NSArray
and NSString
only.pub fn veryShortMonthSymbols(&self) -> Retained<NSArray<NSString>>
NSArray
and NSString
only.pub fn standaloneMonthSymbols(&self) -> Retained<NSArray<NSString>>
NSArray
and NSString
only.pub fn shortStandaloneMonthSymbols(&self) -> Retained<NSArray<NSString>>
NSArray
and NSString
only.pub fn veryShortStandaloneMonthSymbols(&self) -> Retained<NSArray<NSString>>
NSArray
and NSString
only.pub fn weekdaySymbols(&self) -> Retained<NSArray<NSString>>
NSArray
and NSString
only.pub fn shortWeekdaySymbols(&self) -> Retained<NSArray<NSString>>
NSArray
and NSString
only.pub fn veryShortWeekdaySymbols(&self) -> Retained<NSArray<NSString>>
NSArray
and NSString
only.pub fn standaloneWeekdaySymbols(&self) -> Retained<NSArray<NSString>>
NSArray
and NSString
only.pub fn shortStandaloneWeekdaySymbols(&self) -> Retained<NSArray<NSString>>
NSArray
and NSString
only.pub fn veryShortStandaloneWeekdaySymbols(&self) -> Retained<NSArray<NSString>>
NSArray
and NSString
only.pub fn quarterSymbols(&self) -> Retained<NSArray<NSString>>
NSArray
and NSString
only.pub fn shortQuarterSymbols(&self) -> Retained<NSArray<NSString>>
NSArray
and NSString
only.pub fn standaloneQuarterSymbols(&self) -> Retained<NSArray<NSString>>
NSArray
and NSString
only.pub fn shortStandaloneQuarterSymbols(&self) -> Retained<NSArray<NSString>>
NSArray
and NSString
only.pub fn AMSymbol(&self) -> Retained<NSString>
NSString
only.pub fn PMSymbol(&self) -> Retained<NSString>
NSString
only.pub fn minimumRangeOfUnit(&self, unit: NSCalendarUnit) -> NSRange
NSRange
only.pub fn maximumRangeOfUnit(&self, unit: NSCalendarUnit) -> NSRange
NSRange
only.pub fn rangeOfUnit_inUnit_forDate( &self, smaller: NSCalendarUnit, larger: NSCalendarUnit, date: &NSDate, ) -> NSRange
NSDate
and NSRange
only.pub fn ordinalityOfUnit_inUnit_forDate( &self, smaller: NSCalendarUnit, larger: NSCalendarUnit, date: &NSDate, ) -> NSUInteger
NSDate
only.Sourcepub unsafe fn rangeOfUnit_startDate_interval_forDate(
&self,
unit: NSCalendarUnit,
datep: Option<&mut Option<Retained<NSDate>>>,
tip: *mut NSTimeInterval,
date: &NSDate,
) -> bool
Available on crate feature NSDate
only.
pub unsafe fn rangeOfUnit_startDate_interval_forDate( &self, unit: NSCalendarUnit, datep: Option<&mut Option<Retained<NSDate>>>, tip: *mut NSTimeInterval, date: &NSDate, ) -> bool
NSDate
only.§Safety
tip
must be a valid pointer or null.
pub fn dateFromComponents( &self, comps: &NSDateComponents, ) -> Option<Retained<NSDate>>
NSDate
only.pub fn components_fromDate( &self, unit_flags: NSCalendarUnit, date: &NSDate, ) -> Retained<NSDateComponents>
NSDate
only.pub fn dateByAddingComponents_toDate_options( &self, comps: &NSDateComponents, date: &NSDate, opts: NSCalendarOptions, ) -> Option<Retained<NSDate>>
NSDate
only.pub fn components_fromDate_toDate_options( &self, unit_flags: NSCalendarUnit, starting_date: &NSDate, result_date: &NSDate, opts: NSCalendarOptions, ) -> Retained<NSDateComponents>
NSDate
only.Sourcepub unsafe fn getEra_year_month_day_fromDate(
&self,
era_value_pointer: *mut NSInteger,
year_value_pointer: *mut NSInteger,
month_value_pointer: *mut NSInteger,
day_value_pointer: *mut NSInteger,
date: &NSDate,
)
Available on crate feature NSDate
only.
pub unsafe fn getEra_year_month_day_fromDate( &self, era_value_pointer: *mut NSInteger, year_value_pointer: *mut NSInteger, month_value_pointer: *mut NSInteger, day_value_pointer: *mut NSInteger, date: &NSDate, )
NSDate
only.§Safety
era_value_pointer
must be a valid pointer or null.year_value_pointer
must be a valid pointer or null.month_value_pointer
must be a valid pointer or null.day_value_pointer
must be a valid pointer or null.
Sourcepub unsafe fn getEra_yearForWeekOfYear_weekOfYear_weekday_fromDate(
&self,
era_value_pointer: *mut NSInteger,
year_value_pointer: *mut NSInteger,
week_value_pointer: *mut NSInteger,
weekday_value_pointer: *mut NSInteger,
date: &NSDate,
)
Available on crate feature NSDate
only.
pub unsafe fn getEra_yearForWeekOfYear_weekOfYear_weekday_fromDate( &self, era_value_pointer: *mut NSInteger, year_value_pointer: *mut NSInteger, week_value_pointer: *mut NSInteger, weekday_value_pointer: *mut NSInteger, date: &NSDate, )
NSDate
only.§Safety
era_value_pointer
must be a valid pointer or null.year_value_pointer
must be a valid pointer or null.week_value_pointer
must be a valid pointer or null.weekday_value_pointer
must be a valid pointer or null.
Sourcepub unsafe fn getHour_minute_second_nanosecond_fromDate(
&self,
hour_value_pointer: *mut NSInteger,
minute_value_pointer: *mut NSInteger,
second_value_pointer: *mut NSInteger,
nanosecond_value_pointer: *mut NSInteger,
date: &NSDate,
)
Available on crate feature NSDate
only.
pub unsafe fn getHour_minute_second_nanosecond_fromDate( &self, hour_value_pointer: *mut NSInteger, minute_value_pointer: *mut NSInteger, second_value_pointer: *mut NSInteger, nanosecond_value_pointer: *mut NSInteger, date: &NSDate, )
NSDate
only.§Safety
hour_value_pointer
must be a valid pointer or null.minute_value_pointer
must be a valid pointer or null.second_value_pointer
must be a valid pointer or null.nanosecond_value_pointer
must be a valid pointer or null.
pub fn component_fromDate( &self, unit: NSCalendarUnit, date: &NSDate, ) -> NSInteger
NSDate
only.pub fn dateWithEra_year_month_day_hour_minute_second_nanosecond( &self, era_value: NSInteger, year_value: NSInteger, month_value: NSInteger, day_value: NSInteger, hour_value: NSInteger, minute_value: NSInteger, second_value: NSInteger, nanosecond_value: NSInteger, ) -> Option<Retained<NSDate>>
NSDate
only.pub fn dateWithEra_yearForWeekOfYear_weekOfYear_weekday_hour_minute_second_nanosecond( &self, era_value: NSInteger, year_value: NSInteger, week_value: NSInteger, weekday_value: NSInteger, hour_value: NSInteger, minute_value: NSInteger, second_value: NSInteger, nanosecond_value: NSInteger, ) -> Option<Retained<NSDate>>
NSDate
only.pub fn startOfDayForDate(&self, date: &NSDate) -> Retained<NSDate>
NSDate
only.pub fn componentsInTimeZone_fromDate( &self, timezone: &NSTimeZone, date: &NSDate, ) -> Retained<NSDateComponents>
NSDate
and NSTimeZone
only.pub fn compareDate_toDate_toUnitGranularity( &self, date1: &NSDate, date2: &NSDate, unit: NSCalendarUnit, ) -> NSComparisonResult
NSDate
and NSObjCRuntime
only.pub fn isDate_equalToDate_toUnitGranularity( &self, date1: &NSDate, date2: &NSDate, unit: NSCalendarUnit, ) -> bool
NSDate
only.pub fn isDate_inSameDayAsDate(&self, date1: &NSDate, date2: &NSDate) -> bool
NSDate
only.pub fn isDateInToday(&self, date: &NSDate) -> bool
NSDate
only.pub fn isDateInYesterday(&self, date: &NSDate) -> bool
NSDate
only.pub fn isDateInTomorrow(&self, date: &NSDate) -> bool
NSDate
only.pub fn isDateInWeekend(&self, date: &NSDate) -> bool
NSDate
only.Sourcepub unsafe fn rangeOfWeekendStartDate_interval_containingDate(
&self,
datep: Option<&mut Option<Retained<NSDate>>>,
tip: *mut NSTimeInterval,
date: &NSDate,
) -> bool
Available on crate feature NSDate
only.
pub unsafe fn rangeOfWeekendStartDate_interval_containingDate( &self, datep: Option<&mut Option<Retained<NSDate>>>, tip: *mut NSTimeInterval, date: &NSDate, ) -> bool
NSDate
only.§Safety
tip
must be a valid pointer or null.
Sourcepub unsafe fn nextWeekendStartDate_interval_options_afterDate(
&self,
datep: Option<&mut Option<Retained<NSDate>>>,
tip: *mut NSTimeInterval,
options: NSCalendarOptions,
date: &NSDate,
) -> bool
Available on crate feature NSDate
only.
pub unsafe fn nextWeekendStartDate_interval_options_afterDate( &self, datep: Option<&mut Option<Retained<NSDate>>>, tip: *mut NSTimeInterval, options: NSCalendarOptions, date: &NSDate, ) -> bool
NSDate
only.§Safety
tip
must be a valid pointer or null.
pub fn components_fromDateComponents_toDateComponents_options( &self, unit_flags: NSCalendarUnit, starting_date_comp: &NSDateComponents, result_date_comp: &NSDateComponents, options: NSCalendarOptions, ) -> Retained<NSDateComponents>
pub fn dateByAddingUnit_value_toDate_options( &self, unit: NSCalendarUnit, value: NSInteger, date: &NSDate, options: NSCalendarOptions, ) -> Option<Retained<NSDate>>
NSDate
only.pub fn enumerateDatesStartingAfterDate_matchingComponents_options_usingBlock( &self, start: &NSDate, comps: &NSDateComponents, opts: NSCalendarOptions, block: &DynBlock<dyn Fn(*mut NSDate, Bool, NonNull<Bool>) + '_>, )
NSDate
and block2
only.pub fn nextDateAfterDate_matchingComponents_options( &self, date: &NSDate, comps: &NSDateComponents, options: NSCalendarOptions, ) -> Option<Retained<NSDate>>
NSDate
only.pub fn nextDateAfterDate_matchingUnit_value_options( &self, date: &NSDate, unit: NSCalendarUnit, value: NSInteger, options: NSCalendarOptions, ) -> Option<Retained<NSDate>>
NSDate
only.pub fn nextDateAfterDate_matchingHour_minute_second_options( &self, date: &NSDate, hour_value: NSInteger, minute_value: NSInteger, second_value: NSInteger, options: NSCalendarOptions, ) -> Option<Retained<NSDate>>
NSDate
only.pub fn dateBySettingUnit_value_ofDate_options( &self, unit: NSCalendarUnit, v: NSInteger, date: &NSDate, opts: NSCalendarOptions, ) -> Option<Retained<NSDate>>
NSDate
only.pub fn dateBySettingHour_minute_second_ofDate_options( &self, h: NSInteger, m: NSInteger, s: NSInteger, date: &NSDate, opts: NSCalendarOptions, ) -> Option<Retained<NSDate>>
NSDate
only.pub fn date_matchesComponents( &self, date: &NSDate, components: &NSDateComponents, ) -> bool
NSDate
only.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 NSCalendar
impl AsRef<AnyObject> for NSCalendar
Source§impl AsRef<CFCalendar> for NSCalendar
Available on crate feature objc2-core-foundation
only.
impl AsRef<CFCalendar> for NSCalendar
objc2-core-foundation
only.Source§fn as_ref(&self) -> &CFCalendar
fn as_ref(&self) -> &CFCalendar
Source§impl AsRef<NSCalendar> for CFCalendar
Available on crate feature objc2-core-foundation
only.
impl AsRef<NSCalendar> for CFCalendar
objc2-core-foundation
only.Source§fn as_ref(&self) -> &NSCalendar
fn as_ref(&self) -> &NSCalendar
Source§impl AsRef<NSCalendar> for NSCalendar
impl AsRef<NSCalendar> for NSCalendar
Source§impl AsRef<NSObject> for NSCalendar
impl AsRef<NSObject> for NSCalendar
Source§impl Borrow<AnyObject> for NSCalendar
impl Borrow<AnyObject> for NSCalendar
Source§impl Borrow<NSObject> for NSCalendar
impl Borrow<NSObject> for NSCalendar
Source§impl ClassType for NSCalendar
impl ClassType for NSCalendar
Source§const NAME: &'static str = "NSCalendar"
const NAME: &'static str = "NSCalendar"
Source§type ThreadKind = <<NSCalendar as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<NSCalendar as ClassType>::Super as ClassType>::ThreadKind
Source§impl CopyingHelper for NSCalendar
Available on crate feature NSObject
only.
impl CopyingHelper for NSCalendar
NSObject
only.Source§type Result = NSCalendar
type Result = NSCalendar
Self
if the type has no
immutable counterpart. Read moreSource§impl Debug for NSCalendar
impl Debug for NSCalendar
Source§impl Deref for NSCalendar
impl Deref for NSCalendar
Source§impl Hash for NSCalendar
impl Hash for NSCalendar
Source§impl Message for NSCalendar
impl Message for NSCalendar
Source§impl NSCoding for NSCalendar
impl NSCoding for NSCalendar
Source§unsafe fn encodeWithCoder(&self, coder: &NSCoder)
unsafe fn encodeWithCoder(&self, coder: &NSCoder)
NSObject
and NSCoder
only.Source§impl NSCopying for NSCalendar
impl NSCopying for NSCalendar
Source§impl NSObjectProtocol for NSCalendar
impl NSObjectProtocol for NSCalendar
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