#[repr(C)]pub struct UIWritingToolsCoordinator { /* private fields */ }
UIWritingToolsCoordinator
only.Expand description
An object that manages interactions between Writing Tools and your custom text view.
Add a UIWritingToolsCoordinator
object to a custom view when you
want to add Writing Tools support to that view. The coordinator manages
interactions between your view and the Writing Tools UI and back-end
capabilities. When creating a coordinator, you supply a delegate object
to respond to requests from the system and provide needed information.
Your delegate delivers your view’s text to Writing Tools, incorporates
suggested changes back into your text storage, and supports the animations
that Writing Tools creates to show the state of an operation.
Create the UIWritingToolsCoordinator
object when setting up your UI, and
initialize it with a custom object that adopts the UIWritingToolsCoordinator/Delegate
protocol. Add the coordinator to your view using the UIView/addInteraction(_:)
method. When a coordinator is present on a view, the system adds UI elements
to initiate Writing Tools operations.
When defining the delegate, choose an object from your app that has access
to your view and its text storage. You can adopt the UIWritingToolsCoordinator/Delegate
protocol in the view itself, or in another type that your view uses to
manage content. During the interactions with Writing Tools, the delegate
gets and sets the contents of the view’s text storage and supports Writing Tools behaviors.
Note: You don’t need to create an
UIWritingToolsCoordinator
object if you display text using aUITextView
, <doc ://com.apple.documentation/documentation/appkit/nstextview>, <doc ://com.apple.documentation/documentation/swiftui/text>, <doc ://com.apple.documentation/documentation/swiftui/textfield>, or <doc ://com.apple.documentation/documentation/swiftui/texteditor> view. Those views already include the required support to handle Writing Tools interactions.
See also Apple’s documentation
Implementations§
Source§impl UIWritingToolsCoordinator
impl UIWritingToolsCoordinator
Sourcepub unsafe fn isWritingToolsAvailable(mtm: MainThreadMarker) -> bool
pub unsafe fn isWritingToolsAvailable(mtm: MainThreadMarker) -> bool
A Boolean value that indicates whether Writing Tools features are currently available.
The value of this property is true
when Writing Tools features are
available, and false
when they aren’t. Writing Tools support might
be unavailable because of device constraints or because the system isn’t
ready to process Writing Tools requests.
Sourcepub unsafe fn initWithDelegate(
this: Allocated<Self>,
delegate: Option<&ProtocolObject<dyn UIWritingToolsCoordinatorDelegate>>,
) -> Retained<Self>
pub unsafe fn initWithDelegate( this: Allocated<Self>, delegate: Option<&ProtocolObject<dyn UIWritingToolsCoordinatorDelegate>>, ) -> Retained<Self>
Creates a writing tools coordinator and assigns the specified delegate object to it.
- Parameters:
- delegate: An object capable of handling Writing Tools interactions for your view. The delegate must be able to modify your view’s text storage and refresh the view’s layout and appearance.
Create the coordinator object during your view’s initialization, and assign
the object to your view. Use the UIView/addInteraction(_:)
method to add the object to your view.
Sourcepub unsafe fn delegate(
&self,
) -> Option<Retained<ProtocolObject<dyn UIWritingToolsCoordinatorDelegate>>>
pub unsafe fn delegate( &self, ) -> Option<Retained<ProtocolObject<dyn UIWritingToolsCoordinatorDelegate>>>
The object that handles Writing Tools interactions for your view.
Specify this object at initialization time when creating your UIWritingToolsCoordinator
object. The object must adopt the UIWritingToolsCoordinator/Delegate
protocol, and be capable of modifying your view’s text storage and
refreshing the view’s layout and appearance.
Sourcepub unsafe fn effectContainerView(&self) -> Option<Retained<UIView>>
Available on crate features UIResponder
and UIView
only.
pub unsafe fn effectContainerView(&self) -> Option<Retained<UIView>>
UIResponder
and UIView
only.The view that Writing Tools uses to display visual effects during the text-rewriting process.
Writing Tools uses the view in this property to host the visual effects
it creates when making interactive changes to your view’s content.
These visual effects let people know the state of the text and provide
feedback about what’s happening to it. Set this property to a subview
that sits visually above, and covers, all of the text in your custom
text view. If you don’t assign a value to this property, the coordinator
uses the object in its UIInteraction/view
property to host any visual effects.
If you display your view’s text using multiple text containers, implement the
UIWritingToolsCoordinator/Delegate/writingToolsCoordinator(_:requestsSingleContainerSubrangesOf:in:completion:)
method to request multiple previews.
Sourcepub unsafe fn setEffectContainerView(
&self,
effect_container_view: Option<&UIView>,
)
Available on crate features UIResponder
and UIView
only.
pub unsafe fn setEffectContainerView( &self, effect_container_view: Option<&UIView>, )
UIResponder
and UIView
only.This is a weak property.
Setter for effectContainerView
.
Sourcepub unsafe fn decorationContainerView(&self) -> Option<Retained<UIView>>
Available on crate features UIResponder
and UIView
only.
pub unsafe fn decorationContainerView(&self) -> Option<Retained<UIView>>
UIResponder
and UIView
only.The view that Writing Tools uses to display background decorations such as proofreading marks.
Writing Tools uses the view in this property to host proofreading marks
and other visual elements that show any suggested changes. Set this
property to a subview situated visibly below the text in your custom
text view. It’s also satisfactory to place this view visually in front
of the text. Make sure the size of the view is big enough to
cover all of the affected text. If you don’t assign a value to
this property, the coordinator uses the object in its UIInteraction/view
property to host any visual elements.
If you display your view’s text using multiple text containers, implement the
UIWritingToolsCoordinator/Delegate/writingToolsCoordinator(_:requestsSingleContainerSubrangesOf:in:completion:)
and UIWritingToolsCoordinator/Delegate/writingToolsCoordinator(_:requestsDecorationContainerViewFor:in:completion:)
methods to provide separate decoration views for each container.
Sourcepub unsafe fn setDecorationContainerView(
&self,
decoration_container_view: Option<&UIView>,
)
Available on crate features UIResponder
and UIView
only.
pub unsafe fn setDecorationContainerView( &self, decoration_container_view: Option<&UIView>, )
UIResponder
and UIView
only.This is a weak property.
Setter for decorationContainerView
.
Sourcepub unsafe fn state(&self) -> UIWritingToolsCoordinatorState
pub unsafe fn state(&self) -> UIWritingToolsCoordinatorState
The current level of Writing Tools activity in your view.
Use this property to determine when Writing Tools is actively making
changes to your view. During the course of Writing Tools interactions,
the system reports state changes to the delegate’s
UIWritingToolsCoordinator/Delegate/writingToolsCoordinator(_:willChangeTo:completion:)
method and updates this property accordingly.
Sourcepub unsafe fn stopWritingTools(&self)
pub unsafe fn stopWritingTools(&self)
Stops the current Writing Tools operation and dismisses the system UI.
Call this method to abort the current Writing Tools operation. This method dismisses the system’s Writing Tools UI and stops any in-flight interactions with your view. This method does not undo any changes that Writing Tools already made to your view’s content.
Sourcepub unsafe fn preferredBehavior(&self) -> UIWritingToolsBehavior
Available on crate feature UITextInputTraits
only.
pub unsafe fn preferredBehavior(&self) -> UIWritingToolsBehavior
UITextInputTraits
only.The level of Writing Tools support you want the system to provide for your view.
Use this property to request an inline or panel-based experience,
or to disable Writing Tools for your view altogether. The default
value of this property is UIWritingToolsBehavior/default
.
Sourcepub unsafe fn setPreferredBehavior(
&self,
preferred_behavior: UIWritingToolsBehavior,
)
Available on crate feature UITextInputTraits
only.
pub unsafe fn setPreferredBehavior( &self, preferred_behavior: UIWritingToolsBehavior, )
UITextInputTraits
only.Setter for preferredBehavior
.
Sourcepub unsafe fn behavior(&self) -> UIWritingToolsBehavior
Available on crate feature UITextInputTraits
only.
pub unsafe fn behavior(&self) -> UIWritingToolsBehavior
UITextInputTraits
only.The actual level of Writing Tools support the system provides for your view.
The system chooses this value based on the device capabilities, and takes
the value in the preferredBehavior
property into consideration when
making the choice. The value in this property is never the default option,
and is instead one of the specific options such as UIWritingToolsBehavior/none
,
UIWritingToolsBehavior/limited
, or UIWritingToolsBehavior/complete
.
Sourcepub unsafe fn preferredResultOptions(&self) -> UIWritingToolsResultOptions
Available on crate feature UITextInputTraits
only.
pub unsafe fn preferredResultOptions(&self) -> UIWritingToolsResultOptions
UITextInputTraits
only.The type of content you allow Writing Tools to generate for your custom text view.
Writing Tools can create plain text or rich text, and it can format text
using lists or tables as needed. If your view doesn’t support specific
types of content, specify the types you do support in this property.
The default value of this property is UIWritingToolsResultOptions/default
,
which lets the system determine the type of content to generate.
Sourcepub unsafe fn setPreferredResultOptions(
&self,
preferred_result_options: UIWritingToolsResultOptions,
)
Available on crate feature UITextInputTraits
only.
pub unsafe fn setPreferredResultOptions( &self, preferred_result_options: UIWritingToolsResultOptions, )
UITextInputTraits
only.Setter for preferredResultOptions
.
Sourcepub unsafe fn resultOptions(&self) -> UIWritingToolsResultOptions
Available on crate feature UITextInputTraits
only.
pub unsafe fn resultOptions(&self) -> UIWritingToolsResultOptions
UITextInputTraits
only.The type of content the system generates for your custom text view.
This property contains the set of options that Writing Tools outputs
for your view. Writing Tools takes the value in the
UIWritingToolsCoordinator/preferredResultOptions
property into
consideration when determining this value.
Sourcepub unsafe fn updateRange_withText_reason_forContextWithIdentifier(
&self,
range: NSRange,
replacement_text: &NSAttributedString,
reason: UIWritingToolsCoordinatorTextUpdateReason,
context_id: &NSUUID,
)
pub unsafe fn updateRange_withText_reason_forContextWithIdentifier( &self, range: NSRange, replacement_text: &NSAttributedString, reason: UIWritingToolsCoordinatorTextUpdateReason, context_id: &NSUUID, )
Informs the coordinator about changes your app made to the text in the specified context object.
- Parameters:
- range: The range of text to replace. This range is relative to the starting location of the specified context object’s text in your view’s text storage. If you initialized the context object with the entire contents of your view’s text storage, specify the range of text you’re replacing in your text storage. However, if you initialized the context object with only a portion of your view’s text, specify a range that is relative to the starting location of the context object’s text.
- replacementText: The text that replaces the previous content in
range
. Specify an empty string to delete the text in the specified range. - reason: The reason you updated the text.
- contextID: The unique identifier of the context object that contains the text you modified.
If you make any changes to the text Writing Tools is evaluating, call this method to report those changes to your view’s coordinator object. You might make changes in response to an undo command or when someone types into the same part of your view’s text. Calling this method keeps the coordinator object informed of any changes, and ensures it delivers accurate information to its delegate. In response, the coordinator refreshes previews and other information related to your view. If the scope of the update is significantly large, the coordinator can optionally cancel the Writing Tools session altogether.
Use this method to report changes that precisely intersect your context
object’s text. The first time you call this method for a context object,
report changes only to the original attributed string in that object.
If you call this method more than once, report changes to the newly
modified version of that string. Don’t use this method to report changes
to text that comes before or after the context object. If you make
changes before your context object, report those changes separately using the
UIWritingToolsCoordinator/updateForReflowedTextInContextWithIdentifier(_:)
method.
Warning: Failure to call this method for a change can cause Writing Tools to deliver inaccurate information to your delegate and lead to data loss.
Sourcepub unsafe fn updateForReflowedTextInContextWithIdentifier(
&self,
context_id: &NSUUID,
)
pub unsafe fn updateForReflowedTextInContextWithIdentifier( &self, context_id: &NSUUID, )
Informs the coordinator that a change occurred to the view or its text that requires a layout update.
- Parameters:
- contextID: The unique identifier of the context object affected by the change. Pass the identifier for the context object that comes after the changes.
Use this method to inform Writing Tools when the geometry of your view changes, or when the text that precedes one of your context objects changes. Changes to the view’s geometry or text can affect the flow of any remaining text, and require a layout update. Writing Tools uses this method to refresh any layout-dependent information it’s currently tracking. For example, it uses it to refresh the location of proofreading marks it’s displaying in your view.
If a text change affects the text inside a context object, call the
updateRange(_:with:reason:forContextWithIdentifier:)
method to report
that change instead.
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 UIIndirectScribbleInteraction
only.
pub fn class(&self) -> &'static AnyClass
UIIndirectScribbleInteraction
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 UIIndirectScribbleInteraction
only.
pub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
Ivar::load
instead.UIIndirectScribbleInteraction
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 UIIndirectScribbleInteraction
only.
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
UIIndirectScribbleInteraction
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 UIWritingToolsCoordinator
impl AsRef<AnyObject> for UIWritingToolsCoordinator
Source§impl AsRef<NSObject> for UIWritingToolsCoordinator
impl AsRef<NSObject> for UIWritingToolsCoordinator
Source§impl Borrow<AnyObject> for UIWritingToolsCoordinator
impl Borrow<AnyObject> for UIWritingToolsCoordinator
Source§impl Borrow<NSObject> for UIWritingToolsCoordinator
impl Borrow<NSObject> for UIWritingToolsCoordinator
Source§impl ClassType for UIWritingToolsCoordinator
impl ClassType for UIWritingToolsCoordinator
Source§const NAME: &'static str = "UIWritingToolsCoordinator"
const NAME: &'static str = "UIWritingToolsCoordinator"
Source§type ThreadKind = dyn MainThreadOnly
type ThreadKind = dyn MainThreadOnly
Source§impl Debug for UIWritingToolsCoordinator
impl Debug for UIWritingToolsCoordinator
Source§impl Deref for UIWritingToolsCoordinator
impl Deref for UIWritingToolsCoordinator
Source§impl Hash for UIWritingToolsCoordinator
impl Hash for UIWritingToolsCoordinator
Source§impl Message for UIWritingToolsCoordinator
impl Message for UIWritingToolsCoordinator
Source§impl NSObjectProtocol for UIWritingToolsCoordinator
impl NSObjectProtocol for UIWritingToolsCoordinator
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
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 debugDescription(&self) -> Retained<NSObject>
fn debugDescription(&self) -> Retained<NSObject>
Source§impl RefEncode for UIWritingToolsCoordinator
impl RefEncode for UIWritingToolsCoordinator
Source§const ENCODING_REF: Encoding = <NSObject as ::objc2::RefEncode>::ENCODING_REF
const ENCODING_REF: Encoding = <NSObject as ::objc2::RefEncode>::ENCODING_REF
Source§impl UIInteraction for UIWritingToolsCoordinator
impl UIInteraction for UIWritingToolsCoordinator
impl DowncastTarget for UIWritingToolsCoordinator
impl Eq for UIWritingToolsCoordinator
Auto Trait Implementations§
impl !Freeze for UIWritingToolsCoordinator
impl !RefUnwindSafe for UIWritingToolsCoordinator
impl !Send for UIWritingToolsCoordinator
impl !Sync for UIWritingToolsCoordinator
impl !Unpin for UIWritingToolsCoordinator
impl !UnwindSafe for UIWritingToolsCoordinator
Blanket Implementations§
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