pub struct CSLocalizedString { /* private fields */ }CSSearchableItemAttributeSet only.Expand description
Implementations§
Source§impl CSLocalizedString
impl CSLocalizedString
Sourcepub unsafe fn initWithLocalizedStrings(
this: Allocated<Self>,
localized_strings: &NSDictionary,
) -> Retained<Self>
pub unsafe fn initWithLocalizedStrings( this: Allocated<Self>, localized_strings: &NSDictionary, ) -> Retained<Self>
§Safety
localized_strings generic should be of the correct type.
pub unsafe fn localizedString(&self) -> Retained<NSString>
Source§impl CSLocalizedString
Methods declared on superclass NSString.
impl CSLocalizedString
Methods declared on superclass NSString.
Methods from Deref<Target = NSString>§
pub fn length(&self) -> usize
pub fn characterAtIndex(&self, index: usize) -> u16
pub fn substringFromIndex(&self, from: usize) -> Retained<NSString>
pub fn substringToIndex(&self, to: usize) -> Retained<NSString>
pub fn compare(&self, string: &NSString) -> NSComparisonResult
pub fn compare_options( &self, string: &NSString, mask: NSStringCompareOptions, ) -> NSComparisonResult
pub fn caseInsensitiveCompare(&self, string: &NSString) -> NSComparisonResult
pub fn localizedCompare(&self, string: &NSString) -> NSComparisonResult
pub fn localizedCaseInsensitiveCompare( &self, string: &NSString, ) -> NSComparisonResult
pub fn localizedStandardCompare(&self, string: &NSString) -> NSComparisonResult
pub fn isEqualToString(&self, a_string: &NSString) -> bool
pub fn hasPrefix(&self, str: &NSString) -> bool
pub fn hasSuffix(&self, str: &NSString) -> bool
pub fn commonPrefixWithString_options( &self, str: &NSString, mask: NSStringCompareOptions, ) -> Retained<NSString>
pub fn containsString(&self, str: &NSString) -> bool
pub fn localizedCaseInsensitiveContainsString(&self, str: &NSString) -> bool
pub fn localizedStandardContainsString(&self, str: &NSString) -> bool
pub fn stringByAppendingString(&self, a_string: &NSString) -> Retained<NSString>
pub fn doubleValue(&self) -> f64
pub fn floatValue(&self) -> f32
pub fn intValue(&self) -> i32
pub fn integerValue(&self) -> isize
pub fn longLongValue(&self) -> i64
pub fn boolValue(&self) -> bool
pub fn uppercaseString(&self) -> Retained<NSString>
pub fn lowercaseString(&self) -> Retained<NSString>
pub fn capitalizedString(&self) -> Retained<NSString>
pub fn localizedUppercaseString(&self) -> Retained<NSString>
pub fn localizedLowercaseString(&self) -> Retained<NSString>
pub fn localizedCapitalizedString(&self) -> Retained<NSString>
pub fn UTF8String(&self) -> *const i8
pub fn fastestEncoding(&self) -> usize
pub fn smallestEncoding(&self) -> usize
pub fn dataUsingEncoding_allowLossyConversion( &self, encoding: usize, lossy: bool, ) -> Option<Retained<NSData>>
pub fn dataUsingEncoding(&self, encoding: usize) -> Option<Retained<NSData>>
pub fn canBeConvertedToEncoding(&self, encoding: usize) -> bool
pub fn cStringUsingEncoding(&self, encoding: usize) -> *const i8
Sourcepub unsafe fn getCString_maxLength_encoding(
&self,
buffer: NonNull<i8>,
max_buffer_count: usize,
encoding: usize,
) -> bool
pub unsafe fn getCString_maxLength_encoding( &self, buffer: NonNull<i8>, max_buffer_count: usize, encoding: usize, ) -> bool
§Safety
buffer must be a valid pointer.
pub fn maximumLengthOfBytesUsingEncoding(&self, enc: usize) -> usize
pub fn lengthOfBytesUsingEncoding(&self, enc: usize) -> usize
pub fn decomposedStringWithCanonicalMapping(&self) -> Retained<NSString>
pub fn precomposedStringWithCanonicalMapping(&self) -> Retained<NSString>
pub fn decomposedStringWithCompatibilityMapping(&self) -> Retained<NSString>
pub fn precomposedStringWithCompatibilityMapping(&self) -> Retained<NSString>
pub fn componentsSeparatedByString( &self, separator: &NSString, ) -> Retained<NSArray<NSString>>
pub fn stringByPaddingToLength_withString_startingAtIndex( &self, new_length: usize, pad_string: &NSString, pad_index: usize, ) -> Retained<NSString>
pub fn stringByReplacingOccurrencesOfString_withString( &self, target: &NSString, replacement: &NSString, ) -> Retained<NSString>
pub fn stringByApplyingTransform_reverse( &self, transform: &NSString, reverse: bool, ) -> Option<Retained<NSString>>
pub fn writeToURL_atomically_encoding_error( &self, url: &NSURL, use_auxiliary_file: bool, enc: usize, ) -> Result<(), Retained<NSError>>
pub fn writeToFile_atomically_encoding_error( &self, path: &NSString, use_auxiliary_file: bool, enc: usize, ) -> Result<(), Retained<NSError>>
pub fn description(&self) -> Retained<NSString>
pub fn hash(&self) -> usize
pub fn propertyList(&self) -> Retained<AnyObject>
pub fn propertyListFromStringsFileFormat( &self, ) -> Option<Retained<NSDictionary>>
pub fn cString(&self) -> *const i8
pub fn lossyCString(&self) -> *const i8
pub fn cStringLength(&self) -> usize
Sourcepub unsafe fn getCString(&self, bytes: NonNull<i8>)
👎Deprecated: Use -getCString:maxLength:encoding: instead
pub unsafe fn getCString(&self, bytes: NonNull<i8>)
§Safety
bytes must be a valid pointer.
Sourcepub unsafe fn getCString_maxLength(&self, bytes: NonNull<i8>, max_length: usize)
👎Deprecated: Use -getCString:maxLength:encoding: instead
pub unsafe fn getCString_maxLength(&self, bytes: NonNull<i8>, max_length: usize)
§Safety
bytes must be a valid pointer.
pub fn writeToFile_atomically( &self, path: &NSString, use_auxiliary_file: bool, ) -> bool
pub fn writeToURL_atomically(&self, url: &NSURL, atomically: bool) -> bool
Sourcepub unsafe fn getCharacters(&self, buffer: NonNull<u16>)
pub unsafe fn getCharacters(&self, buffer: NonNull<u16>)
§Safety
buffer must be a valid pointer.
pub fn stringByRemovingPercentEncoding(&self) -> Option<Retained<NSString>>
pub fn stringByAddingPercentEscapesUsingEncoding( &self, enc: usize, ) -> Option<Retained<NSString>>
pub fn stringByReplacingPercentEscapesUsingEncoding( &self, enc: usize, ) -> Option<Retained<NSString>>
Sourcepub fn len_utf16(&self) -> usize
pub fn len_utf16(&self) -> usize
The number of UTF-16 code units in the string.
See also NSString::len.
pub fn is_empty(&self) -> bool
Sourcepub unsafe fn to_str<'r, 's, 'p>(&'s self, pool: AutoreleasePool<'p>) -> &'r strwhere
's: 'r,
'p: 'r,
pub unsafe fn to_str<'r, 's, 'p>(&'s self, pool: AutoreleasePool<'p>) -> &'r strwhere
's: 'r,
'p: 'r,
Convert the string into a string slice.
The signature of this method can be a bit confusing, as it contains
several lifetimes; the lifetime 's of the NSString, the lifetime
'p of the current autorelease pool and the lifetime 'r of the
returned string slice.
In general, this method converts the string to a newly allocated UTF-8 string, autoreleases the buffer, and returns a slice pointer to this internal buffer, which will become invalid once the autorelease pool is popped. So the lifetime of the return value is bound to the current autorelease pool.
However, as an optimization, this method may choose to instead return
an internal reference to the NSString when it can, and when the
string is immutable, and that is why the lifetime of the returned
string slice is also bound to the string itself.
You should prefer the to_string method or the
Display implementation over this method when
possible.
§Safety
The pool must be the innermost pool, see the documentation on
autoreleasepool.
§Examples
Get the string slice of the NSString, and compare it with another
inside an autorelease pool.
use objc2_foundation::NSString;
use objc2::rc::autoreleasepool;
let string = NSString::from_str("foo");
autoreleasepool(|pool| {
// SAFETY: The str is not used outside the autorelease pool.
assert_eq!(unsafe { string.to_str(pool) }, "foo");
});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 CSLocalizedString
impl AsRef<AnyObject> for CSLocalizedString
Source§impl AsRef<CSLocalizedString> for CSLocalizedString
impl AsRef<CSLocalizedString> for CSLocalizedString
Source§impl AsRef<NSObject> for CSLocalizedString
impl AsRef<NSObject> for CSLocalizedString
Source§impl AsRef<NSString> for CSLocalizedString
impl AsRef<NSString> for CSLocalizedString
Source§impl Borrow<AnyObject> for CSLocalizedString
impl Borrow<AnyObject> for CSLocalizedString
Source§impl Borrow<NSObject> for CSLocalizedString
impl Borrow<NSObject> for CSLocalizedString
Source§impl Borrow<NSString> for CSLocalizedString
impl Borrow<NSString> for CSLocalizedString
Source§impl ClassType for CSLocalizedString
impl ClassType for CSLocalizedString
Source§const NAME: &'static str = "CSLocalizedString"
const NAME: &'static str = "CSLocalizedString"
Source§type ThreadKind = <<CSLocalizedString as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<CSLocalizedString as ClassType>::Super as ClassType>::ThreadKind
Source§impl CopyingHelper for CSLocalizedString
impl CopyingHelper for CSLocalizedString
Source§type Result = CSLocalizedString
type Result = CSLocalizedString
Self if the type has no
immutable counterpart. Read moreSource§impl Debug for CSLocalizedString
impl Debug for CSLocalizedString
Source§impl Deref for CSLocalizedString
impl Deref for CSLocalizedString
Source§impl Hash for CSLocalizedString
impl Hash for CSLocalizedString
Source§impl Message for CSLocalizedString
impl Message for CSLocalizedString
Source§impl MutableCopyingHelper for CSLocalizedString
impl MutableCopyingHelper for CSLocalizedString
Source§type Result = NSMutableString
type Result = NSMutableString
Self if the type has no
mutable counterpart. Read moreSource§impl NSCoding for CSLocalizedString
impl NSCoding for CSLocalizedString
Source§impl NSCopying for CSLocalizedString
impl NSCopying for CSLocalizedString
Source§impl NSMutableCopying for CSLocalizedString
impl NSMutableCopying for CSLocalizedString
Source§impl NSObjectProtocol for CSLocalizedString
impl NSObjectProtocol for CSLocalizedString
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