1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

extern_protocol!(
    #[cfg(feature = "UITextInputTraits")]
    pub unsafe trait UIKeyInput: UITextInputTraits + IsMainThreadOnly {
        #[method(hasText)]
        unsafe fn hasText(&self) -> bool;

        #[method(insertText:)]
        unsafe fn insertText(&self, text: &NSString);

        #[method(deleteBackward)]
        unsafe fn deleteBackward(&self);
    }

    #[cfg(feature = "UITextInputTraits")]
    unsafe impl ProtocolType for dyn UIKeyInput {}
);

// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct UITextStorageDirection(pub NSInteger);
impl UITextStorageDirection {
    #[doc(alias = "UITextStorageDirectionForward")]
    pub const Forward: Self = Self(0);
    #[doc(alias = "UITextStorageDirectionBackward")]
    pub const Backward: Self = Self(1);
}

unsafe impl Encode for UITextStorageDirection {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for UITextStorageDirection {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct UITextLayoutDirection(pub NSInteger);
impl UITextLayoutDirection {
    #[doc(alias = "UITextLayoutDirectionRight")]
    pub const Right: Self = Self(2);
    #[doc(alias = "UITextLayoutDirectionLeft")]
    pub const Left: Self = Self(3);
    #[doc(alias = "UITextLayoutDirectionUp")]
    pub const Up: Self = Self(4);
    #[doc(alias = "UITextLayoutDirectionDown")]
    pub const Down: Self = Self(5);
}

unsafe impl Encode for UITextLayoutDirection {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for UITextLayoutDirection {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

// NS_TYPED_ENUM
pub type UITextDirection = NSInteger;

// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct UITextGranularity(pub NSInteger);
impl UITextGranularity {
    #[doc(alias = "UITextGranularityCharacter")]
    pub const Character: Self = Self(0);
    #[doc(alias = "UITextGranularityWord")]
    pub const Word: Self = Self(1);
    #[doc(alias = "UITextGranularitySentence")]
    pub const Sentence: Self = Self(2);
    #[doc(alias = "UITextGranularityParagraph")]
    pub const Paragraph: Self = Self(3);
    #[doc(alias = "UITextGranularityLine")]
    pub const Line: Self = Self(4);
    #[doc(alias = "UITextGranularityDocument")]
    pub const Document: Self = Self(5);
}

unsafe impl Encode for UITextGranularity {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for UITextGranularity {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct UIDictationPhrase;

    unsafe impl ClassType for UIDictationPhrase {
        type Super = NSObject;
        type Mutability = MainThreadOnly;
    }
);

unsafe impl NSObjectProtocol for UIDictationPhrase {}

extern_methods!(
    unsafe impl UIDictationPhrase {
        #[method_id(@__retain_semantics Other text)]
        pub unsafe fn text(&self) -> Retained<NSString>;

        #[method_id(@__retain_semantics Other alternativeInterpretations)]
        pub unsafe fn alternativeInterpretations(&self) -> Option<Retained<NSArray<NSString>>>;
    }
);

extern_methods!(
    /// Methods declared on superclass `NSObject`
    unsafe impl UIDictationPhrase {
        #[method_id(@__retain_semantics Init init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[method_id(@__retain_semantics New new)]
        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
    }
);

extern_class!(
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct UITextInputAssistantItem;

    unsafe impl ClassType for UITextInputAssistantItem {
        type Super = NSObject;
        type Mutability = MainThreadOnly;
    }
);

unsafe impl NSObjectProtocol for UITextInputAssistantItem {}

extern_methods!(
    unsafe impl UITextInputAssistantItem {
        #[method(allowsHidingShortcuts)]
        pub unsafe fn allowsHidingShortcuts(&self) -> bool;

        #[method(setAllowsHidingShortcuts:)]
        pub unsafe fn setAllowsHidingShortcuts(&self, allows_hiding_shortcuts: bool);

        #[cfg(feature = "UIBarButtonItemGroup")]
        #[method_id(@__retain_semantics Other leadingBarButtonGroups)]
        pub unsafe fn leadingBarButtonGroups(&self) -> Retained<NSArray<UIBarButtonItemGroup>>;

        #[cfg(feature = "UIBarButtonItemGroup")]
        #[method(setLeadingBarButtonGroups:)]
        pub unsafe fn setLeadingBarButtonGroups(
            &self,
            leading_bar_button_groups: &NSArray<UIBarButtonItemGroup>,
        );

        #[cfg(feature = "UIBarButtonItemGroup")]
        #[method_id(@__retain_semantics Other trailingBarButtonGroups)]
        pub unsafe fn trailingBarButtonGroups(&self) -> Retained<NSArray<UIBarButtonItemGroup>>;

        #[cfg(feature = "UIBarButtonItemGroup")]
        #[method(setTrailingBarButtonGroups:)]
        pub unsafe fn setTrailingBarButtonGroups(
            &self,
            trailing_bar_button_groups: &NSArray<UIBarButtonItemGroup>,
        );
    }
);

extern_methods!(
    /// Methods declared on superclass `NSObject`
    unsafe impl UITextInputAssistantItem {
        #[method_id(@__retain_semantics Init init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[method_id(@__retain_semantics New new)]
        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
    }
);

extern_class!(
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct UITextPlaceholder;

    unsafe impl ClassType for UITextPlaceholder {
        type Super = NSObject;
        type Mutability = MainThreadOnly;
    }
);

unsafe impl NSObjectProtocol for UITextPlaceholder {}

extern_methods!(
    unsafe impl UITextPlaceholder {
        #[method_id(@__retain_semantics Other rects)]
        pub unsafe fn rects(&self) -> Retained<NSArray<UITextSelectionRect>>;
    }
);

extern_methods!(
    /// Methods declared on superclass `NSObject`
    unsafe impl UITextPlaceholder {
        #[method_id(@__retain_semantics Init init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[method_id(@__retain_semantics New new)]
        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
    }
);

// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct UITextAlternativeStyle(pub NSInteger);
impl UITextAlternativeStyle {
    #[doc(alias = "UITextAlternativeStyleNone")]
    pub const None: Self = Self(0);
    #[doc(alias = "UITextAlternativeStyleLowConfidence")]
    pub const LowConfidence: Self = Self(1);
}

unsafe impl Encode for UITextAlternativeStyle {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for UITextAlternativeStyle {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_protocol!(
    #[cfg(feature = "UITextInputTraits")]
    pub unsafe trait UITextInput: UIKeyInput + IsMainThreadOnly {
        #[method_id(@__retain_semantics Other textInRange:)]
        unsafe fn textInRange(&self, range: &UITextRange) -> Option<Retained<NSString>>;

        #[method(replaceRange:withText:)]
        unsafe fn replaceRange_withText(&self, range: &UITextRange, text: &NSString);

        #[method_id(@__retain_semantics Other selectedTextRange)]
        unsafe fn selectedTextRange(&self) -> Option<Retained<UITextRange>>;

        #[method(setSelectedTextRange:)]
        unsafe fn setSelectedTextRange(&self, selected_text_range: Option<&UITextRange>);

        #[method_id(@__retain_semantics Other markedTextRange)]
        unsafe fn markedTextRange(&self) -> Option<Retained<UITextRange>>;

        #[method_id(@__retain_semantics Other markedTextStyle)]
        unsafe fn markedTextStyle(
            &self,
        ) -> Option<Retained<NSDictionary<NSAttributedStringKey, AnyObject>>>;

        #[method(setMarkedTextStyle:)]
        unsafe fn setMarkedTextStyle(
            &self,
            marked_text_style: Option<&NSDictionary<NSAttributedStringKey, AnyObject>>,
        );

        #[method(setMarkedText:selectedRange:)]
        unsafe fn setMarkedText_selectedRange(
            &self,
            marked_text: Option<&NSString>,
            selected_range: NSRange,
        );

        #[method(unmarkText)]
        unsafe fn unmarkText(&self);

        #[method_id(@__retain_semantics Other beginningOfDocument)]
        unsafe fn beginningOfDocument(&self) -> Retained<UITextPosition>;

        #[method_id(@__retain_semantics Other endOfDocument)]
        unsafe fn endOfDocument(&self) -> Retained<UITextPosition>;

        #[method_id(@__retain_semantics Other textRangeFromPosition:toPosition:)]
        unsafe fn textRangeFromPosition_toPosition(
            &self,
            from_position: &UITextPosition,
            to_position: &UITextPosition,
        ) -> Option<Retained<UITextRange>>;

        #[method_id(@__retain_semantics Other positionFromPosition:offset:)]
        unsafe fn positionFromPosition_offset(
            &self,
            position: &UITextPosition,
            offset: NSInteger,
        ) -> Option<Retained<UITextPosition>>;

        #[method_id(@__retain_semantics Other positionFromPosition:inDirection:offset:)]
        unsafe fn positionFromPosition_inDirection_offset(
            &self,
            position: &UITextPosition,
            direction: UITextLayoutDirection,
            offset: NSInteger,
        ) -> Option<Retained<UITextPosition>>;

        #[method(comparePosition:toPosition:)]
        unsafe fn comparePosition_toPosition(
            &self,
            position: &UITextPosition,
            other: &UITextPosition,
        ) -> NSComparisonResult;

        #[method(offsetFromPosition:toPosition:)]
        unsafe fn offsetFromPosition_toPosition(
            &self,
            from: &UITextPosition,
            to_position: &UITextPosition,
        ) -> NSInteger;

        #[method_id(@__retain_semantics Other inputDelegate)]
        unsafe fn inputDelegate(&self)
            -> Option<Retained<ProtocolObject<dyn UITextInputDelegate>>>;

        #[method(setInputDelegate:)]
        unsafe fn setInputDelegate(
            &self,
            input_delegate: Option<&ProtocolObject<dyn UITextInputDelegate>>,
        );

        #[method_id(@__retain_semantics Other tokenizer)]
        unsafe fn tokenizer(&self) -> Retained<ProtocolObject<dyn UITextInputTokenizer>>;

        #[method_id(@__retain_semantics Other positionWithinRange:farthestInDirection:)]
        unsafe fn positionWithinRange_farthestInDirection(
            &self,
            range: &UITextRange,
            direction: UITextLayoutDirection,
        ) -> Option<Retained<UITextPosition>>;

        #[method_id(@__retain_semantics Other characterRangeByExtendingPosition:inDirection:)]
        unsafe fn characterRangeByExtendingPosition_inDirection(
            &self,
            position: &UITextPosition,
            direction: UITextLayoutDirection,
        ) -> Option<Retained<UITextRange>>;

        #[cfg(feature = "NSText")]
        #[method(baseWritingDirectionForPosition:inDirection:)]
        unsafe fn baseWritingDirectionForPosition_inDirection(
            &self,
            position: &UITextPosition,
            direction: UITextStorageDirection,
        ) -> NSWritingDirection;

        #[cfg(feature = "NSText")]
        #[method(setBaseWritingDirection:forRange:)]
        unsafe fn setBaseWritingDirection_forRange(
            &self,
            writing_direction: NSWritingDirection,
            range: &UITextRange,
        );

        #[method(firstRectForRange:)]
        unsafe fn firstRectForRange(&self, range: &UITextRange) -> CGRect;

        #[method(caretRectForPosition:)]
        unsafe fn caretRectForPosition(&self, position: &UITextPosition) -> CGRect;

        #[method_id(@__retain_semantics Other selectionRectsForRange:)]
        unsafe fn selectionRectsForRange(
            &self,
            range: &UITextRange,
        ) -> Retained<NSArray<UITextSelectionRect>>;

        #[method_id(@__retain_semantics Other closestPositionToPoint:)]
        unsafe fn closestPositionToPoint(&self, point: CGPoint)
            -> Option<Retained<UITextPosition>>;

        #[method_id(@__retain_semantics Other closestPositionToPoint:withinRange:)]
        unsafe fn closestPositionToPoint_withinRange(
            &self,
            point: CGPoint,
            range: &UITextRange,
        ) -> Option<Retained<UITextPosition>>;

        #[method_id(@__retain_semantics Other characterRangeAtPoint:)]
        unsafe fn characterRangeAtPoint(&self, point: CGPoint) -> Option<Retained<UITextRange>>;

        #[optional]
        #[method(shouldChangeTextInRange:replacementText:)]
        unsafe fn shouldChangeTextInRange_replacementText(
            &self,
            range: &UITextRange,
            text: &NSString,
        ) -> bool;

        #[optional]
        #[method_id(@__retain_semantics Other textStylingAtPosition:inDirection:)]
        unsafe fn textStylingAtPosition_inDirection(
            &self,
            position: &UITextPosition,
            direction: UITextStorageDirection,
        ) -> Option<Retained<NSDictionary<NSAttributedStringKey, AnyObject>>>;

        #[optional]
        #[method_id(@__retain_semantics Other positionWithinRange:atCharacterOffset:)]
        unsafe fn positionWithinRange_atCharacterOffset(
            &self,
            range: &UITextRange,
            offset: NSInteger,
        ) -> Option<Retained<UITextPosition>>;

        #[optional]
        #[method(characterOffsetOfPosition:withinRange:)]
        unsafe fn characterOffsetOfPosition_withinRange(
            &self,
            position: &UITextPosition,
            range: &UITextRange,
        ) -> NSInteger;

        #[cfg(all(feature = "UIResponder", feature = "UIView"))]
        #[optional]
        #[method_id(@__retain_semantics Other textInputView)]
        unsafe fn textInputView(&self) -> Retained<UIView>;

        #[optional]
        #[method(selectionAffinity)]
        unsafe fn selectionAffinity(&self) -> UITextStorageDirection;

        #[optional]
        #[method(setSelectionAffinity:)]
        unsafe fn setSelectionAffinity(&self, selection_affinity: UITextStorageDirection);

        #[optional]
        #[method(insertDictationResult:)]
        unsafe fn insertDictationResult(&self, dictation_result: &NSArray<UIDictationPhrase>);

        #[optional]
        #[method(dictationRecordingDidEnd)]
        unsafe fn dictationRecordingDidEnd(&self);

        #[optional]
        #[method(dictationRecognitionFailed)]
        unsafe fn dictationRecognitionFailed(&self);

        #[optional]
        #[method_id(@__retain_semantics Other insertDictationResultPlaceholder)]
        unsafe fn insertDictationResultPlaceholder(&self) -> Retained<AnyObject>;

        #[optional]
        #[method(frameForDictationResultPlaceholder:)]
        unsafe fn frameForDictationResultPlaceholder(&self, placeholder: &AnyObject) -> CGRect;

        #[optional]
        #[method(removeDictationResultPlaceholder:willInsertResult:)]
        unsafe fn removeDictationResultPlaceholder_willInsertResult(
            &self,
            placeholder: &AnyObject,
            will_insert_result: bool,
        );

        #[optional]
        #[method(insertText:alternatives:style:)]
        unsafe fn insertText_alternatives_style(
            &self,
            text: &NSString,
            alternatives: &NSArray<NSString>,
            style: UITextAlternativeStyle,
        );

        #[optional]
        #[method(setAttributedMarkedText:selectedRange:)]
        unsafe fn setAttributedMarkedText_selectedRange(
            &self,
            marked_text: Option<&NSAttributedString>,
            selected_range: NSRange,
        );

        #[optional]
        #[method_id(@__retain_semantics Other insertTextPlaceholderWithSize:)]
        unsafe fn insertTextPlaceholderWithSize(&self, size: CGSize)
            -> Retained<UITextPlaceholder>;

        #[optional]
        #[method(removeTextPlaceholder:)]
        unsafe fn removeTextPlaceholder(&self, text_placeholder: &UITextPlaceholder);

        #[optional]
        #[method(beginFloatingCursorAtPoint:)]
        unsafe fn beginFloatingCursorAtPoint(&self, point: CGPoint);

        #[optional]
        #[method(updateFloatingCursorAtPoint:)]
        unsafe fn updateFloatingCursorAtPoint(&self, point: CGPoint);

        #[optional]
        #[method(endFloatingCursor)]
        unsafe fn endFloatingCursor(&self);

        #[optional]
        #[method(caretTransformForPosition:)]
        unsafe fn caretTransformForPosition(&self, position: &UITextPosition) -> CGAffineTransform;

        #[cfg(all(feature = "UIMenu", feature = "UIMenuElement"))]
        #[optional]
        #[method_id(@__retain_semantics Other editMenuForTextRange:suggestedActions:)]
        unsafe fn editMenuForTextRange_suggestedActions(
            &self,
            text_range: &UITextRange,
            suggested_actions: &NSArray<UIMenuElement>,
        ) -> Option<Retained<UIMenu>>;

        #[cfg(feature = "UIEditMenuInteraction")]
        #[optional]
        #[method(willPresentEditMenuWithAnimator:)]
        unsafe fn willPresentEditMenuWithAnimator(
            &self,
            animator: &ProtocolObject<dyn UIEditMenuInteractionAnimating>,
        );

        #[cfg(feature = "UIEditMenuInteraction")]
        #[optional]
        #[method(willDismissEditMenuWithAnimator:)]
        unsafe fn willDismissEditMenuWithAnimator(
            &self,
            animator: &ProtocolObject<dyn UIEditMenuInteractionAnimating>,
        );
    }

    #[cfg(feature = "UITextInputTraits")]
    unsafe impl ProtocolType for dyn UITextInput {}
);

extern "C" {
    pub static UITextInputTextBackgroundColorKey: &'static NSString;
}

extern "C" {
    pub static UITextInputTextColorKey: &'static NSString;
}

extern "C" {
    pub static UITextInputTextFontKey: &'static NSString;
}

extern_class!(
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct UITextPosition;

    unsafe impl ClassType for UITextPosition {
        type Super = NSObject;
        type Mutability = MainThreadOnly;
    }
);

unsafe impl NSObjectProtocol for UITextPosition {}

extern_methods!(
    unsafe impl UITextPosition {}
);

extern_methods!(
    /// Methods declared on superclass `NSObject`
    unsafe impl UITextPosition {
        #[method_id(@__retain_semantics Init init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[method_id(@__retain_semantics New new)]
        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
    }
);

extern_class!(
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct UITextRange;

    unsafe impl ClassType for UITextRange {
        type Super = NSObject;
        type Mutability = MainThreadOnly;
    }
);

unsafe impl NSObjectProtocol for UITextRange {}

extern_methods!(
    unsafe impl UITextRange {
        #[method(isEmpty)]
        pub unsafe fn isEmpty(&self) -> bool;

        #[method_id(@__retain_semantics Other start)]
        pub unsafe fn start(&self) -> Retained<UITextPosition>;

        #[method_id(@__retain_semantics Other end)]
        pub unsafe fn end(&self) -> Retained<UITextPosition>;
    }
);

extern_methods!(
    /// Methods declared on superclass `NSObject`
    unsafe impl UITextRange {
        #[method_id(@__retain_semantics Init init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[method_id(@__retain_semantics New new)]
        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
    }
);

extern_class!(
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct UITextSelectionRect;

    unsafe impl ClassType for UITextSelectionRect {
        type Super = NSObject;
        type Mutability = MainThreadOnly;
    }
);

unsafe impl NSObjectProtocol for UITextSelectionRect {}

extern_methods!(
    unsafe impl UITextSelectionRect {
        #[method(rect)]
        pub unsafe fn rect(&self) -> CGRect;

        #[cfg(feature = "NSText")]
        #[method(writingDirection)]
        pub unsafe fn writingDirection(&self) -> NSWritingDirection;

        #[method(containsStart)]
        pub unsafe fn containsStart(&self) -> bool;

        #[method(containsEnd)]
        pub unsafe fn containsEnd(&self) -> bool;

        #[method(isVertical)]
        pub unsafe fn isVertical(&self) -> bool;

        #[method(transform)]
        pub unsafe fn transform(&self) -> CGAffineTransform;
    }
);

extern_methods!(
    /// Methods declared on superclass `NSObject`
    unsafe impl UITextSelectionRect {
        #[method_id(@__retain_semantics Init init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[method_id(@__retain_semantics New new)]
        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
    }
);

extern_protocol!(
    pub unsafe trait UITextInputDelegate: NSObjectProtocol + IsMainThreadOnly {
        #[cfg(feature = "UITextInputTraits")]
        #[method(selectionWillChange:)]
        unsafe fn selectionWillChange(&self, text_input: Option<&ProtocolObject<dyn UITextInput>>);

        #[cfg(feature = "UITextInputTraits")]
        #[method(selectionDidChange:)]
        unsafe fn selectionDidChange(&self, text_input: Option<&ProtocolObject<dyn UITextInput>>);

        #[cfg(feature = "UITextInputTraits")]
        #[method(textWillChange:)]
        unsafe fn textWillChange(&self, text_input: Option<&ProtocolObject<dyn UITextInput>>);

        #[cfg(feature = "UITextInputTraits")]
        #[method(textDidChange:)]
        unsafe fn textDidChange(&self, text_input: Option<&ProtocolObject<dyn UITextInput>>);
    }

    unsafe impl ProtocolType for dyn UITextInputDelegate {}
);

extern_protocol!(
    pub unsafe trait UITextInputTokenizer: NSObjectProtocol + IsMainThreadOnly {
        #[method_id(@__retain_semantics Other rangeEnclosingPosition:withGranularity:inDirection:)]
        unsafe fn rangeEnclosingPosition_withGranularity_inDirection(
            &self,
            position: &UITextPosition,
            granularity: UITextGranularity,
            direction: UITextDirection,
        ) -> Option<Retained<UITextRange>>;

        #[method(isPosition:atBoundary:inDirection:)]
        unsafe fn isPosition_atBoundary_inDirection(
            &self,
            position: &UITextPosition,
            granularity: UITextGranularity,
            direction: UITextDirection,
        ) -> bool;

        #[method_id(@__retain_semantics Other positionFromPosition:toBoundary:inDirection:)]
        unsafe fn positionFromPosition_toBoundary_inDirection(
            &self,
            position: &UITextPosition,
            granularity: UITextGranularity,
            direction: UITextDirection,
        ) -> Option<Retained<UITextPosition>>;

        #[method(isPosition:withinTextUnit:inDirection:)]
        unsafe fn isPosition_withinTextUnit_inDirection(
            &self,
            position: &UITextPosition,
            granularity: UITextGranularity,
            direction: UITextDirection,
        ) -> bool;
    }

    unsafe impl ProtocolType for dyn UITextInputTokenizer {}
);

extern_class!(
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct UITextInputStringTokenizer;

    unsafe impl ClassType for UITextInputStringTokenizer {
        type Super = NSObject;
        type Mutability = MainThreadOnly;
    }
);

unsafe impl NSObjectProtocol for UITextInputStringTokenizer {}

unsafe impl UITextInputTokenizer for UITextInputStringTokenizer {}

extern_methods!(
    unsafe impl UITextInputStringTokenizer {
        #[cfg(all(feature = "UIResponder", feature = "UITextInputTraits"))]
        #[method_id(@__retain_semantics Init initWithTextInput:)]
        pub unsafe fn initWithTextInput(
            this: Allocated<Self>,
            text_input: &UIResponder,
        ) -> Retained<Self>;
    }
);

extern_methods!(
    /// Methods declared on superclass `NSObject`
    unsafe impl UITextInputStringTokenizer {
        #[method_id(@__retain_semantics Init init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[method_id(@__retain_semantics New new)]
        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
    }
);

extern_class!(
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct UITextInputMode;

    unsafe impl ClassType for UITextInputMode {
        type Super = NSObject;
        type Mutability = MainThreadOnly;
    }
);

unsafe impl NSCoding for UITextInputMode {}

unsafe impl NSObjectProtocol for UITextInputMode {}

unsafe impl NSSecureCoding for UITextInputMode {}

extern_methods!(
    unsafe impl UITextInputMode {
        #[method_id(@__retain_semantics Other primaryLanguage)]
        pub unsafe fn primaryLanguage(&self) -> Option<Retained<NSString>>;

        #[deprecated]
        #[method_id(@__retain_semantics Other currentInputMode)]
        pub unsafe fn currentInputMode(mtm: MainThreadMarker) -> Option<Retained<UITextInputMode>>;

        #[method_id(@__retain_semantics Other activeInputModes)]
        pub unsafe fn activeInputModes(mtm: MainThreadMarker)
            -> Retained<NSArray<UITextInputMode>>;
    }
);

extern_methods!(
    /// Methods declared on superclass `NSObject`
    unsafe impl UITextInputMode {
        #[method_id(@__retain_semantics Init init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[method_id(@__retain_semantics New new)]
        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
    }
);

extern "C" {
    pub static UITextInputCurrentInputModeDidChangeNotification: &'static NSNotificationName;
}