#[repr(C)]pub struct NSSharingService { /* private fields */ }
NSSharingService
only.Expand description
NSSharingService can be used to share items to different kinds of local and remote services. Items are objects which respond to the NSPasteboardWriting protocol, like NSURL, NSImage or NSString. If an NSURL is a file URL (point to a video for example), then the content of the file will be shared. If the URL is remote, then the URL itself will be shared.
See also Apple’s documentation
Implementations§
Source§impl NSSharingService
impl NSSharingService
pub unsafe fn delegate( &self, mtm: MainThreadMarker, ) -> Option<Retained<ProtocolObject<dyn NSSharingServiceDelegate>>>
Sourcepub unsafe fn setDelegate(
&self,
delegate: Option<&ProtocolObject<dyn NSSharingServiceDelegate>>,
)
pub unsafe fn setDelegate( &self, delegate: Option<&ProtocolObject<dyn NSSharingServiceDelegate>>, )
This is a weak property.
Setter for delegate
.
pub unsafe fn title(&self) -> Retained<NSString>
pub unsafe fn image(&self) -> Retained<NSImage>
NSImage
only.pub unsafe fn alternateImage(&self) -> Option<Retained<NSImage>>
NSImage
only.Title of the service in the Share menu. Can be modified.
Sourcepub unsafe fn setMenuItemTitle(&self, menu_item_title: &NSString)
pub unsafe fn setMenuItemTitle(&self, menu_item_title: &NSString)
Setter for menuItemTitle
.
Sourcepub unsafe fn recipients(&self) -> Option<Retained<NSArray<NSString>>>
pub unsafe fn recipients(&self) -> Option<Retained<NSArray<NSString>>>
NSArray of NSString objects representing handles (example: email adresses)
Sourcepub unsafe fn setRecipients(&self, recipients: Option<&NSArray<NSString>>)
pub unsafe fn setRecipients(&self, recipients: Option<&NSArray<NSString>>)
Setter for recipients
.
pub unsafe fn subject(&self) -> Option<Retained<NSString>>
Sourcepub unsafe fn setSubject(&self, subject: Option<&NSString>)
pub unsafe fn setSubject(&self, subject: Option<&NSString>)
Setter for subject
.
Sourcepub unsafe fn messageBody(&self) -> Option<Retained<NSString>>
pub unsafe fn messageBody(&self) -> Option<Retained<NSString>>
Message body as string
Sourcepub unsafe fn permanentLink(&self) -> Option<Retained<NSURL>>
pub unsafe fn permanentLink(&self) -> Option<Retained<NSURL>>
URL to access the post on Facebook, Twitter, Sina Weibo, etc. (also known as permalink)
Sourcepub unsafe fn accountName(&self) -> Option<Retained<NSString>>
pub unsafe fn accountName(&self) -> Option<Retained<NSString>>
Account name used for sending on Twitter or Sina Weibo
Sourcepub unsafe fn attachmentFileURLs(&self) -> Option<Retained<NSArray<NSURL>>>
pub unsafe fn attachmentFileURLs(&self) -> Option<Retained<NSArray<NSURL>>>
NSArray of NSURL objects representing the files that were shared
Sourcepub unsafe fn sharingServicesForItems(
items: &NSArray,
) -> Retained<NSArray<NSSharingService>>
👎Deprecated: Use -[NSSharingServicePicker standardShareMenuItem] instead.
pub unsafe fn sharingServicesForItems( items: &NSArray, ) -> Retained<NSArray<NSSharingService>>
Returns a list of NSSharingServices which could share all the provided items together. sharingServicesForItems can be used to build a custom UI, or to populate a contextual NSMenu. The items represent the objects to be shared and must conform to the <NSPasteboardWriting
protocol or be an NSItemProvider or an NSDocument. (e.g. NSString, NSImage, NSURL, etc.)
Sourcepub unsafe fn sharingServiceNamed(
service_name: &NSSharingServiceName,
) -> Option<Retained<NSSharingService>>
pub unsafe fn sharingServiceNamed( service_name: &NSSharingServiceName, ) -> Option<Retained<NSSharingService>>
Returns an NSSharingService representing one of the built-in services.
Sourcepub unsafe fn initWithTitle_image_alternateImage_handler(
this: Allocated<Self>,
title: &NSString,
image: &NSImage,
alternate_image: Option<&NSImage>,
block: &DynBlock<dyn Fn()>,
) -> Retained<Self>
Available on crate features NSImage
and block2
only.
pub unsafe fn initWithTitle_image_alternateImage_handler( this: Allocated<Self>, title: &NSString, image: &NSImage, alternate_image: Option<&NSImage>, block: &DynBlock<dyn Fn()>, ) -> Retained<Self>
NSImage
and block2
only.Creates a custom NSSharingService object. Custom sharing services can be added to the NSSharingServicePicker with the sharingServicePicker:sharingServicesForItems:proposedSharingServices: delegate method.
Sourcepub unsafe fn init(this: Allocated<Self>) -> Retained<Self>
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>
Use -initWithTitle:image:alternateImage:handler: instead
Sourcepub unsafe fn canPerformWithItems(&self, items: Option<&NSArray>) -> bool
pub unsafe fn canPerformWithItems(&self, items: Option<&NSArray>) -> bool
Returns whether a service can do something with all the provided items. This can be used to validate a custom UI such as a dedicated Twitter button. If items is nil, the method will return YES when the service is configured. Therefore you could call it once at launch time with nil items to check whether to display the button or not, and then with real items to enable and disable the button depending on the context or selection.
The items represent the objects to be shared and must conform to the <NSPasteboardWriting
protocol or be an NSItemProvider or an NSDocument. (e.g. NSString, NSImage, NSURL, etc.)
Sourcepub unsafe fn performWithItems(&self, items: &NSArray)
pub unsafe fn performWithItems(&self, items: &NSArray)
Manually performs the service on the provided items. In most cases this will display a sharing window.
The items represent the objects to be shared and must conform to the <NSPasteboardWriting
protocol or be an NSItemProvider or an NSDocument. (e.g. NSString, NSImage, NSURL, etc.)
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
Available on crate feature NSAccessibilityConstants
only.
pub fn class(&self) -> &'static AnyClass
NSAccessibilityConstants
only.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.Available on crate feature NSAccessibilityConstants
only.
pub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
Ivar::load
instead.NSAccessibilityConstants
only.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,
Available on crate feature NSAccessibilityConstants
only.
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
NSAccessibilityConstants
only.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 NSSharingService
impl AsRef<AnyObject> for NSSharingService
Source§impl AsRef<NSObject> for NSSharingService
impl AsRef<NSObject> for NSSharingService
Source§impl AsRef<NSSharingService> for NSSharingService
impl AsRef<NSSharingService> for NSSharingService
Source§impl Borrow<AnyObject> for NSSharingService
impl Borrow<AnyObject> for NSSharingService
Source§impl Borrow<NSObject> for NSSharingService
impl Borrow<NSObject> for NSSharingService
Source§impl ClassType for NSSharingService
impl ClassType for NSSharingService
Source§const NAME: &'static str = "NSSharingService"
const NAME: &'static str = "NSSharingService"
Source§type ThreadKind = <<NSSharingService as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<NSSharingService as ClassType>::Super as ClassType>::ThreadKind
Source§impl Debug for NSSharingService
impl Debug for NSSharingService
Source§impl Deref for NSSharingService
impl Deref for NSSharingService
Source§impl Hash for NSSharingService
impl Hash for NSSharingService
Source§impl Message for NSSharingService
impl Message for NSSharingService
Source§impl NSObjectProtocol for NSSharingService
impl NSObjectProtocol for NSSharingService
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