1#![allow(non_upper_case_globals)]
11
12use crate::base::{id, nil, BOOL, NO, SEL};
13use bitflags::bitflags;
14use block::Block;
15use libc;
16use objc::{class, msg_send, sel, sel_impl};
17use std::os::raw::c_void;
18use std::ptr;
19
20#[cfg(target_pointer_width = "32")]
21pub type NSInteger = libc::c_int;
22#[cfg(target_pointer_width = "32")]
23pub type NSUInteger = libc::c_uint;
24
25#[cfg(target_pointer_width = "64")]
26pub type NSInteger = libc::c_long;
27#[cfg(target_pointer_width = "64")]
28pub type NSUInteger = libc::c_ulong;
29
30pub const NSIntegerMax: NSInteger = NSInteger::max_value();
31pub const NSNotFound: NSInteger = NSIntegerMax;
32
33const UTF8_ENCODING: usize = 4;
34
35#[cfg(target_os = "macos")]
36mod macos {
37 use crate::base::id;
38 use core_graphics_types::base::CGFloat;
39 use core_graphics_types::geometry::CGRect;
40 use objc::{self, class, msg_send, sel, sel_impl};
41 use std::mem;
42
43 #[repr(C)]
44 #[derive(Copy, Clone)]
45 pub struct NSPoint {
46 pub x: CGFloat,
47 pub y: CGFloat,
48 }
49
50 impl NSPoint {
51 #[inline]
52 pub fn new(x: CGFloat, y: CGFloat) -> NSPoint {
53 NSPoint { x, y }
54 }
55 }
56
57 unsafe impl objc::Encode for NSPoint {
58 fn encode() -> objc::Encoding {
59 let encoding = format!(
60 "{{CGPoint={}{}}}",
61 CGFloat::encode().as_str(),
62 CGFloat::encode().as_str()
63 );
64 unsafe { objc::Encoding::from_str(&encoding) }
65 }
66 }
67
68 #[repr(C)]
69 #[derive(Copy, Clone)]
70 pub struct NSSize {
71 pub width: CGFloat,
72 pub height: CGFloat,
73 }
74
75 impl NSSize {
76 #[inline]
77 pub fn new(width: CGFloat, height: CGFloat) -> NSSize {
78 NSSize { width, height }
79 }
80 }
81
82 unsafe impl objc::Encode for NSSize {
83 fn encode() -> objc::Encoding {
84 let encoding = format!(
85 "{{CGSize={}{}}}",
86 CGFloat::encode().as_str(),
87 CGFloat::encode().as_str()
88 );
89 unsafe { objc::Encoding::from_str(&encoding) }
90 }
91 }
92
93 #[repr(C)]
94 #[derive(Copy, Clone)]
95 pub struct NSRect {
96 pub origin: NSPoint,
97 pub size: NSSize,
98 }
99
100 impl NSRect {
101 #[inline]
102 pub fn new(origin: NSPoint, size: NSSize) -> NSRect {
103 NSRect { origin, size }
104 }
105
106 #[inline]
107 pub fn as_CGRect(&self) -> &CGRect {
108 unsafe { mem::transmute::<&NSRect, &CGRect>(self) }
109 }
110
111 #[inline]
112 pub fn inset(&self, x: CGFloat, y: CGFloat) -> NSRect {
113 unsafe { NSInsetRect(*self, x, y) }
114 }
115 }
116
117 unsafe impl objc::Encode for NSRect {
118 fn encode() -> objc::Encoding {
119 let encoding = format!(
120 "{{CGRect={}{}}}",
121 NSPoint::encode().as_str(),
122 NSSize::encode().as_str()
123 );
124 unsafe { objc::Encoding::from_str(&encoding) }
125 }
126 }
127
128 #[repr(u32)]
130 pub enum NSRectEdge {
131 NSRectMinXEdge,
132 NSRectMinYEdge,
133 NSRectMaxXEdge,
134 NSRectMaxYEdge,
135 }
136
137 #[cfg_attr(feature = "link", link(name = "Foundation", kind = "framework"))]
138 extern "C" {
139 fn NSInsetRect(rect: NSRect, x: CGFloat, y: CGFloat) -> NSRect;
140 }
141
142 pub trait NSValue: Sized {
143 unsafe fn valueWithPoint(_: Self, point: NSPoint) -> id {
144 msg_send![class!(NSValue), valueWithPoint: point]
145 }
146
147 unsafe fn valueWithSize(_: Self, size: NSSize) -> id {
148 msg_send![class!(NSValue), valueWithSize: size]
149 }
150 }
151
152 impl NSValue for id {}
153}
154
155#[cfg(target_os = "macos")]
156pub use self::macos::*;
157
158#[repr(C)]
159#[derive(Copy, Clone)]
160pub struct NSRange {
161 pub location: NSUInteger,
162 pub length: NSUInteger,
163}
164
165impl NSRange {
166 #[inline]
167 pub fn new(location: NSUInteger, length: NSUInteger) -> NSRange {
168 NSRange { location, length }
169 }
170}
171
172#[cfg_attr(feature = "link", link(name = "Foundation", kind = "framework"))]
173extern "C" {
174 pub static NSDefaultRunLoopMode: id;
175}
176
177pub trait NSAutoreleasePool: Sized {
178 unsafe fn new(_: Self) -> id {
179 msg_send![class!(NSAutoreleasePool), new]
180 }
181
182 unsafe fn autorelease(self) -> Self;
183 unsafe fn drain(self);
184}
185
186impl NSAutoreleasePool for id {
187 unsafe fn autorelease(self) -> id {
188 msg_send![self, autorelease]
189 }
190
191 unsafe fn drain(self) {
192 msg_send![self, drain]
193 }
194}
195
196#[repr(C)]
197#[derive(Copy, Clone)]
198pub struct NSOperatingSystemVersion {
199 pub majorVersion: NSUInteger,
200 pub minorVersion: NSUInteger,
201 pub patchVersion: NSUInteger,
202}
203
204impl NSOperatingSystemVersion {
205 #[inline]
206 pub fn new(
207 majorVersion: NSUInteger,
208 minorVersion: NSUInteger,
209 patchVersion: NSUInteger,
210 ) -> NSOperatingSystemVersion {
211 NSOperatingSystemVersion {
212 majorVersion,
213 minorVersion,
214 patchVersion,
215 }
216 }
217}
218
219pub trait NSProcessInfo: Sized {
220 unsafe fn processInfo(_: Self) -> id {
221 msg_send![class!(NSProcessInfo), processInfo]
222 }
223
224 unsafe fn systemUptime(self) -> NSTimeInterval;
225 unsafe fn processName(self) -> id;
226 unsafe fn operatingSystemVersion(self) -> NSOperatingSystemVersion;
227 unsafe fn isOperatingSystemAtLeastVersion(self, version: NSOperatingSystemVersion) -> bool;
228}
229
230impl NSProcessInfo for id {
231 unsafe fn processName(self) -> id {
232 msg_send![self, processName]
233 }
234
235 unsafe fn systemUptime(self) -> NSTimeInterval {
236 msg_send![self, systemUptime]
237 }
238
239 unsafe fn operatingSystemVersion(self) -> NSOperatingSystemVersion {
240 msg_send![self, operatingSystemVersion]
241 }
242
243 unsafe fn isOperatingSystemAtLeastVersion(self, version: NSOperatingSystemVersion) -> bool {
244 msg_send![self, isOperatingSystemAtLeastVersion: version]
245 }
246}
247
248pub type NSTimeInterval = libc::c_double;
249
250pub trait NSArray: Sized {
251 unsafe fn array(_: Self) -> id {
252 msg_send![class!(NSArray), array]
253 }
254
255 unsafe fn arrayWithObjects(_: Self, objects: &[id]) -> id {
256 msg_send![class!(NSArray), arrayWithObjects:objects.as_ptr()
257 count:objects.len()]
258 }
259
260 unsafe fn arrayWithObject(_: Self, object: id) -> id {
261 msg_send![class!(NSArray), arrayWithObject: object]
262 }
263
264 unsafe fn init(self) -> id;
265
266 unsafe fn count(self) -> NSUInteger;
267
268 unsafe fn arrayByAddingObjectFromArray(self, object: id) -> id;
269 unsafe fn arrayByAddingObjectsFromArray(self, objects: id) -> id;
270 unsafe fn objectAtIndex(self, index: NSUInteger) -> id;
271}
272
273impl NSArray for id {
274 unsafe fn init(self) -> id {
275 msg_send![self, init]
276 }
277
278 unsafe fn count(self) -> NSUInteger {
279 msg_send![self, count]
280 }
281
282 unsafe fn arrayByAddingObjectFromArray(self, object: id) -> id {
283 msg_send![self, arrayByAddingObjectFromArray: object]
284 }
285
286 unsafe fn arrayByAddingObjectsFromArray(self, objects: id) -> id {
287 msg_send![self, arrayByAddingObjectsFromArray: objects]
288 }
289
290 unsafe fn objectAtIndex(self, index: NSUInteger) -> id {
291 msg_send![self, objectAtIndex: index]
292 }
293}
294
295pub trait NSDictionary: Sized {
296 unsafe fn dictionary(_: Self) -> id {
297 msg_send![class!(NSDictionary), dictionary]
298 }
299
300 unsafe fn dictionaryWithContentsOfFile_(_: Self, path: id) -> id {
301 msg_send![class!(NSDictionary), dictionaryWithContentsOfFile: path]
302 }
303
304 unsafe fn dictionaryWithContentsOfURL_(_: Self, aURL: id) -> id {
305 msg_send![class!(NSDictionary), dictionaryWithContentsOfURL: aURL]
306 }
307
308 unsafe fn dictionaryWithDictionary_(_: Self, otherDictionary: id) -> id {
309 msg_send![
310 class!(NSDictionary),
311 dictionaryWithDictionary: otherDictionary
312 ]
313 }
314
315 unsafe fn dictionaryWithObject_forKey_(_: Self, anObject: id, aKey: id) -> id {
316 msg_send![class!(NSDictionary), dictionaryWithObject:anObject forKey:aKey]
317 }
318
319 unsafe fn dictionaryWithObjects_forKeys_(_: Self, objects: id, keys: id) -> id {
320 msg_send![class!(NSDictionary), dictionaryWithObjects:objects forKeys:keys]
321 }
322
323 unsafe fn dictionaryWithObjects_forKeys_count_(
324 _: Self,
325 objects: *const id,
326 keys: *const id,
327 count: NSUInteger,
328 ) -> id {
329 msg_send![class!(NSDictionary), dictionaryWithObjects:objects forKeys:keys count:count]
330 }
331
332 unsafe fn dictionaryWithObjectsAndKeys_(_: Self, firstObject: id) -> id {
333 msg_send![
334 class!(NSDictionary),
335 dictionaryWithObjectsAndKeys: firstObject
336 ]
337 }
338
339 unsafe fn init(self) -> id;
340 unsafe fn initWithContentsOfFile_(self, path: id) -> id;
341 unsafe fn initWithContentsOfURL_(self, aURL: id) -> id;
342 unsafe fn initWithDictionary_(self, otherDictionary: id) -> id;
343 unsafe fn initWithDictionary_copyItems_(self, otherDictionary: id, flag: BOOL) -> id;
344 unsafe fn initWithObjects_forKeys_(self, objects: id, keys: id) -> id;
345 unsafe fn initWithObjects_forKeys_count_(self, objects: id, keys: id, count: NSUInteger) -> id;
346 unsafe fn initWithObjectsAndKeys_(self, firstObject: id) -> id;
347
348 unsafe fn sharedKeySetForKeys_(_: Self, keys: id) -> id {
349 msg_send![class!(NSDictionary), sharedKeySetForKeys: keys]
350 }
351
352 unsafe fn count(self) -> NSUInteger;
353
354 unsafe fn isEqualToDictionary_(self, otherDictionary: id) -> BOOL;
355
356 unsafe fn allKeys(self) -> id;
357 unsafe fn allKeysForObject_(self, anObject: id) -> id;
358 unsafe fn allValues(self) -> id;
359 unsafe fn objectForKey_(self, aKey: id) -> id;
360 unsafe fn objectForKeyedSubscript_(self, key: id) -> id;
361 unsafe fn objectsForKeys_notFoundMarker_(self, keys: id, anObject: id) -> id;
362 unsafe fn valueForKey_(self, key: id) -> id;
363
364 unsafe fn keyEnumerator(self) -> id;
365 unsafe fn objectEnumerator(self) -> id;
366 unsafe fn enumerateKeysAndObjectsUsingBlock_(self, block: *mut Block<(id, id, *mut BOOL), ()>);
367 unsafe fn enumerateKeysAndObjectsWithOptions_usingBlock_(
368 self,
369 opts: NSEnumerationOptions,
370 block: *mut Block<(id, id, *mut BOOL), ()>,
371 );
372
373 unsafe fn keysSortedByValueUsingSelector_(self, comparator: SEL) -> id;
374 unsafe fn keysSortedByValueUsingComparator_(self, cmptr: NSComparator) -> id;
375 unsafe fn keysSortedByValueWithOptions_usingComparator_(
376 self,
377 opts: NSEnumerationOptions,
378 cmptr: NSComparator,
379 ) -> id;
380
381 unsafe fn keysOfEntriesPassingTest_(
382 self,
383 predicate: *mut Block<(id, id, *mut BOOL), BOOL>,
384 ) -> id;
385 unsafe fn keysOfEntriesWithOptions_PassingTest_(
386 self,
387 opts: NSEnumerationOptions,
388 predicate: *mut Block<(id, id, *mut BOOL), BOOL>,
389 ) -> id;
390
391 unsafe fn writeToFile_atomically_(self, path: id, flag: BOOL) -> BOOL;
392 unsafe fn writeToURL_atomically_(self, aURL: id, flag: BOOL) -> BOOL;
393
394 unsafe fn fileCreationDate(self) -> id;
395 unsafe fn fileExtensionHidden(self) -> BOOL;
396 unsafe fn fileGroupOwnerAccountID(self) -> id;
397 unsafe fn fileGroupOwnerAccountName(self) -> id;
398 unsafe fn fileIsAppendOnly(self) -> BOOL;
399 unsafe fn fileIsImmutable(self) -> BOOL;
400 unsafe fn fileModificationDate(self) -> id;
401 unsafe fn fileOwnerAccountID(self) -> id;
402 unsafe fn fileOwnerAccountName(self) -> id;
403 unsafe fn filePosixPermissions(self) -> NSUInteger;
404 unsafe fn fileSize(self) -> libc::c_ulonglong;
405 unsafe fn fileSystemFileNumber(self) -> NSUInteger;
406 unsafe fn fileSystemNumber(self) -> NSInteger;
407 unsafe fn fileType(self) -> id;
408
409 unsafe fn description(self) -> id;
410 unsafe fn descriptionInStringsFileFormat(self) -> id;
411 unsafe fn descriptionWithLocale_(self, locale: id) -> id;
412 unsafe fn descriptionWithLocale_indent_(self, locale: id, indent: NSUInteger) -> id;
413}
414
415impl NSDictionary for id {
416 unsafe fn init(self) -> id {
417 msg_send![self, init]
418 }
419
420 unsafe fn initWithContentsOfFile_(self, path: id) -> id {
421 msg_send![self, initWithContentsOfFile: path]
422 }
423
424 unsafe fn initWithContentsOfURL_(self, aURL: id) -> id {
425 msg_send![self, initWithContentsOfURL: aURL]
426 }
427
428 unsafe fn initWithDictionary_(self, otherDictionary: id) -> id {
429 msg_send![self, initWithDictionary: otherDictionary]
430 }
431
432 unsafe fn initWithDictionary_copyItems_(self, otherDictionary: id, flag: BOOL) -> id {
433 msg_send![self, initWithDictionary:otherDictionary copyItems:flag]
434 }
435
436 unsafe fn initWithObjects_forKeys_(self, objects: id, keys: id) -> id {
437 msg_send![self, initWithObjects:objects forKeys:keys]
438 }
439
440 unsafe fn initWithObjects_forKeys_count_(self, objects: id, keys: id, count: NSUInteger) -> id {
441 msg_send![self, initWithObjects:objects forKeys:keys count:count]
442 }
443
444 unsafe fn initWithObjectsAndKeys_(self, firstObject: id) -> id {
445 msg_send![self, initWithObjectsAndKeys: firstObject]
446 }
447
448 unsafe fn count(self) -> NSUInteger {
449 msg_send![self, count]
450 }
451
452 unsafe fn isEqualToDictionary_(self, otherDictionary: id) -> BOOL {
453 msg_send![self, isEqualToDictionary: otherDictionary]
454 }
455
456 unsafe fn allKeys(self) -> id {
457 msg_send![self, allKeys]
458 }
459
460 unsafe fn allKeysForObject_(self, anObject: id) -> id {
461 msg_send![self, allKeysForObject: anObject]
462 }
463
464 unsafe fn allValues(self) -> id {
465 msg_send![self, allValues]
466 }
467
468 unsafe fn objectForKey_(self, aKey: id) -> id {
469 msg_send![self, objectForKey: aKey]
470 }
471
472 unsafe fn objectForKeyedSubscript_(self, key: id) -> id {
473 msg_send![self, objectForKeyedSubscript: key]
474 }
475
476 unsafe fn objectsForKeys_notFoundMarker_(self, keys: id, anObject: id) -> id {
477 msg_send![self, objectsForKeys:keys notFoundMarker:anObject]
478 }
479
480 unsafe fn valueForKey_(self, key: id) -> id {
481 msg_send![self, valueForKey: key]
482 }
483
484 unsafe fn keyEnumerator(self) -> id {
485 msg_send![self, keyEnumerator]
486 }
487
488 unsafe fn objectEnumerator(self) -> id {
489 msg_send![self, objectEnumerator]
490 }
491
492 unsafe fn enumerateKeysAndObjectsUsingBlock_(self, block: *mut Block<(id, id, *mut BOOL), ()>) {
493 msg_send![self, enumerateKeysAndObjectsUsingBlock: block]
494 }
495
496 unsafe fn enumerateKeysAndObjectsWithOptions_usingBlock_(
497 self,
498 opts: NSEnumerationOptions,
499 block: *mut Block<(id, id, *mut BOOL), ()>,
500 ) {
501 msg_send![self, enumerateKeysAndObjectsWithOptions:opts usingBlock:block]
502 }
503
504 unsafe fn keysSortedByValueUsingSelector_(self, comparator: SEL) -> id {
505 msg_send![self, keysSortedByValueUsingSelector: comparator]
506 }
507
508 unsafe fn keysSortedByValueUsingComparator_(self, cmptr: NSComparator) -> id {
509 msg_send![self, keysSortedByValueUsingComparator: cmptr]
510 }
511
512 unsafe fn keysSortedByValueWithOptions_usingComparator_(
513 self,
514 opts: NSEnumerationOptions,
515 cmptr: NSComparator,
516 ) -> id {
517 let rv: id = msg_send![self, keysSortedByValueWithOptions:opts usingComparator:cmptr];
518 rv
519 }
520
521 unsafe fn keysOfEntriesPassingTest_(
522 self,
523 predicate: *mut Block<(id, id, *mut BOOL), BOOL>,
524 ) -> id {
525 msg_send![self, keysOfEntriesPassingTest: predicate]
526 }
527
528 unsafe fn keysOfEntriesWithOptions_PassingTest_(
529 self,
530 opts: NSEnumerationOptions,
531 predicate: *mut Block<(id, id, *mut BOOL), BOOL>,
532 ) -> id {
533 msg_send![self, keysOfEntriesWithOptions:opts PassingTest:predicate]
534 }
535
536 unsafe fn writeToFile_atomically_(self, path: id, flag: BOOL) -> BOOL {
537 msg_send![self, writeToFile:path atomically:flag]
538 }
539
540 unsafe fn writeToURL_atomically_(self, aURL: id, flag: BOOL) -> BOOL {
541 msg_send![self, writeToURL:aURL atomically:flag]
542 }
543
544 unsafe fn fileCreationDate(self) -> id {
545 msg_send![self, fileCreationDate]
546 }
547
548 unsafe fn fileExtensionHidden(self) -> BOOL {
549 msg_send![self, fileExtensionHidden]
550 }
551
552 unsafe fn fileGroupOwnerAccountID(self) -> id {
553 msg_send![self, fileGroupOwnerAccountID]
554 }
555
556 unsafe fn fileGroupOwnerAccountName(self) -> id {
557 msg_send![self, fileGroupOwnerAccountName]
558 }
559
560 unsafe fn fileIsAppendOnly(self) -> BOOL {
561 msg_send![self, fileIsAppendOnly]
562 }
563
564 unsafe fn fileIsImmutable(self) -> BOOL {
565 msg_send![self, fileIsImmutable]
566 }
567
568 unsafe fn fileModificationDate(self) -> id {
569 msg_send![self, fileModificationDate]
570 }
571
572 unsafe fn fileOwnerAccountID(self) -> id {
573 msg_send![self, fileOwnerAccountID]
574 }
575
576 unsafe fn fileOwnerAccountName(self) -> id {
577 msg_send![self, fileOwnerAccountName]
578 }
579
580 unsafe fn filePosixPermissions(self) -> NSUInteger {
581 msg_send![self, filePosixPermissions]
582 }
583
584 unsafe fn fileSize(self) -> libc::c_ulonglong {
585 msg_send![self, fileSize]
586 }
587
588 unsafe fn fileSystemFileNumber(self) -> NSUInteger {
589 msg_send![self, fileSystemFileNumber]
590 }
591
592 unsafe fn fileSystemNumber(self) -> NSInteger {
593 msg_send![self, fileSystemNumber]
594 }
595
596 unsafe fn fileType(self) -> id {
597 msg_send![self, fileType]
598 }
599
600 unsafe fn description(self) -> id {
601 msg_send![self, description]
602 }
603
604 unsafe fn descriptionInStringsFileFormat(self) -> id {
605 msg_send![self, descriptionInStringsFileFormat]
606 }
607
608 unsafe fn descriptionWithLocale_(self, locale: id) -> id {
609 msg_send![self, descriptionWithLocale: locale]
610 }
611
612 unsafe fn descriptionWithLocale_indent_(self, locale: id, indent: NSUInteger) -> id {
613 msg_send![self, descriptionWithLocale:locale indent:indent]
614 }
615}
616
617bitflags! {
618 #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
619 pub struct NSEnumerationOptions: libc::c_ulonglong {
620 const NSEnumerationConcurrent = 1 << 0;
621 const NSEnumerationReverse = 1 << 1;
622 }
623}
624
625pub type NSComparator = *mut Block<(id, id), NSComparisonResult>;
626
627#[repr(isize)]
628#[derive(Clone, Copy, Debug, Eq, PartialEq)]
629pub enum NSComparisonResult {
630 NSOrderedAscending = -1,
631 NSOrderedSame = 0,
632 NSOrderedDescending = 1,
633}
634
635pub trait NSString: Sized {
636 unsafe fn alloc(_: Self) -> id {
637 msg_send![class!(NSString), alloc]
638 }
639
640 unsafe fn stringByAppendingString_(self, other: id) -> id;
641 unsafe fn init_str(self, string: &str) -> Self;
642 unsafe fn UTF8String(self) -> *const libc::c_char;
643 unsafe fn len(self) -> usize;
644 unsafe fn isEqualToString(self, string: &str) -> bool;
645 unsafe fn substringWithRange(self, range: NSRange) -> id;
646}
647
648impl NSString for id {
649 unsafe fn isEqualToString(self, other: &str) -> bool {
650 let other = NSString::alloc(nil).init_str(other);
651 let rv: BOOL = msg_send![self, isEqualToString: other];
652 rv != NO
653 }
654
655 unsafe fn stringByAppendingString_(self, other: id) -> id {
656 msg_send![self, stringByAppendingString: other]
657 }
658
659 unsafe fn init_str(self, string: &str) -> id {
660 msg_send![self,
661 initWithBytes:string.as_ptr()
662 length:string.len()
663 encoding:UTF8_ENCODING as id]
664 }
665
666 unsafe fn len(self) -> usize {
667 msg_send![self, lengthOfBytesUsingEncoding: UTF8_ENCODING]
668 }
669
670 unsafe fn UTF8String(self) -> *const libc::c_char {
671 msg_send![self, UTF8String]
672 }
673
674 unsafe fn substringWithRange(self, range: NSRange) -> id {
675 msg_send![self, substringWithRange: range]
676 }
677}
678
679pub trait NSDate: Sized {
680 unsafe fn distantPast(_: Self) -> id {
681 msg_send![class!(NSDate), distantPast]
682 }
683
684 unsafe fn distantFuture(_: Self) -> id {
685 msg_send![class!(NSDate), distantFuture]
686 }
687}
688
689impl NSDate for id {}
690
691#[repr(C)]
692struct NSFastEnumerationState {
693 pub state: libc::c_ulong,
694 pub items_ptr: *mut id,
695 pub mutations_ptr: *mut libc::c_ulong,
696 pub extra: [libc::c_ulong; 5],
697}
698
699const NS_FAST_ENUM_BUF_SIZE: usize = 16;
700
701pub struct NSFastIterator {
702 state: NSFastEnumerationState,
703 buffer: [id; NS_FAST_ENUM_BUF_SIZE],
704 mut_val: Option<libc::c_ulong>,
705 len: usize,
706 idx: usize,
707 object: id,
708}
709
710impl Iterator for NSFastIterator {
711 type Item = id;
712
713 fn next(&mut self) -> Option<id> {
714 if self.idx >= self.len {
715 self.len = unsafe {
716 msg_send![self.object, countByEnumeratingWithState:&mut self.state objects:self.buffer.as_mut_ptr() count:NS_FAST_ENUM_BUF_SIZE]
717 };
718 self.idx = 0;
719 }
720
721 let new_mut = unsafe { *self.state.mutations_ptr };
722
723 if let Some(old_mut) = self.mut_val {
724 assert!(
725 old_mut == new_mut,
726 "The collection was mutated while being enumerated"
727 );
728 }
729
730 if self.idx < self.len {
731 let object = unsafe { *self.state.items_ptr.add(self.idx) };
732 self.mut_val = Some(new_mut);
733 self.idx += 1;
734 Some(object)
735 } else {
736 None
737 }
738 }
739}
740
741pub trait NSFastEnumeration: Sized {
742 unsafe fn iter(self) -> NSFastIterator;
743}
744
745impl NSFastEnumeration for id {
746 unsafe fn iter(self) -> NSFastIterator {
747 NSFastIterator {
748 state: NSFastEnumerationState {
749 state: 0,
750 items_ptr: ptr::null_mut(),
751 mutations_ptr: ptr::null_mut(),
752 extra: [0; 5],
753 },
754 buffer: [nil; NS_FAST_ENUM_BUF_SIZE],
755 mut_val: None,
756 len: 0,
757 idx: 0,
758 object: self,
759 }
760 }
761}
762
763pub trait NSRunLoop: Sized {
764 unsafe fn currentRunLoop() -> Self;
765
766 unsafe fn performSelector_target_argument_order_modes_(
767 self,
768 aSelector: SEL,
769 target: id,
770 anArgument: id,
771 order: NSUInteger,
772 modes: id,
773 );
774}
775
776impl NSRunLoop for id {
777 unsafe fn currentRunLoop() -> id {
778 msg_send![class!(NSRunLoop), currentRunLoop]
779 }
780
781 unsafe fn performSelector_target_argument_order_modes_(
782 self,
783 aSelector: SEL,
784 target: id,
785 anArgument: id,
786 order: NSUInteger,
787 modes: id,
788 ) {
789 msg_send![self, performSelector:aSelector
790 target:target
791 argument:anArgument
792 order:order
793 modes:modes]
794 }
795}
796
797bitflags! {
798 #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
799 pub struct NSURLBookmarkCreationOptions: NSUInteger {
800 const NSURLBookmarkCreationPreferFileIDResolution = 1 << 8;
801 const NSURLBookmarkCreationMinimalBookmark = 1 << 9;
802 const NSURLBookmarkCreationSuitableForBookmarkFile = 1 << 10;
803 const NSURLBookmarkCreationWithSecurityScope = 1 << 11;
804 const NSURLBookmarkCreationSecurityScopeAllowOnlyReadAccess = 1 << 12;
805 }
806}
807
808pub type NSURLBookmarkFileCreationOptions = NSURLBookmarkCreationOptions;
809
810bitflags! {
811 #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
812 pub struct NSURLBookmarkResolutionOptions: NSUInteger {
813 const NSURLBookmarkResolutionWithoutUI = 1 << 8;
814 const NSURLBookmarkResolutionWithoutMounting = 1 << 9;
815 const NSURLBookmarkResolutionWithSecurityScope = 1 << 10;
816 }
817}
818
819pub trait NSURL: Sized {
820 unsafe fn alloc(_: Self) -> id;
821
822 unsafe fn URLWithString_(_: Self, string: id) -> id;
823 unsafe fn initWithString_(self, string: id) -> id;
824 unsafe fn URLWithString_relativeToURL_(_: Self, string: id, url: id) -> id;
825 unsafe fn initWithString_relativeToURL_(self, string: id, url: id) -> id;
826 unsafe fn fileURLWithPath_isDirectory_(_: Self, path: id, is_dir: BOOL) -> id;
827 unsafe fn initFileURLWithPath_isDirectory_(self, path: id, is_dir: BOOL) -> id;
828 unsafe fn fileURLWithPath_relativeToURL_(_: Self, path: id, url: id) -> id;
829 unsafe fn initFileURLWithPath_relativeToURL_(self, path: id, url: id) -> id;
830 unsafe fn fileURLWithPath_isDirectory_relativeToURL_(
831 _: Self,
832 path: id,
833 is_dir: BOOL,
834 url: id,
835 ) -> id;
836 unsafe fn initFileURLWithPath_isDirectory_relativeToURL_(
837 self,
838 path: id,
839 is_dir: BOOL,
840 url: id,
841 ) -> id;
842 unsafe fn fileURLWithPath_(_: Self, path: id) -> id;
843 unsafe fn initFileURLWithPath_(self, path: id) -> id;
844 unsafe fn fileURLWithPathComponents_(
845 _: Self,
846 path_components: id, ) -> id;
848 unsafe fn URLByResolvingAliasFileAtURL_options_error_(
849 _: Self,
850 url: id,
851 options: NSURLBookmarkResolutionOptions,
852 error: *mut id, ) -> id;
854 unsafe fn URLByResolvingBookmarkData_options_relativeToURL_bookmarkDataIsStale_error_(
855 _: Self,
856 data: id, options: NSURLBookmarkResolutionOptions,
858 relative_to_url: id,
859 is_stale: *mut BOOL,
860 error: *mut id, ) -> id;
862 unsafe fn initByResolvingBookmarkData_options_relativeToURL_bookmarkDataIsStale_error_(
863 self,
864 data: id, options: NSURLBookmarkResolutionOptions,
866 relative_to_url: id,
867 is_stale: *mut BOOL,
868 error: *mut id, ) -> id;
870 unsafe fn absoluteURLWithDataRepresentation_relativeToURL_(
874 _: Self,
875 data: id, url: id,
877 ) -> id;
878 unsafe fn initAbsoluteURLWithDataRepresentation_relativeToURL_(
879 self,
880 data: id, url: id,
882 ) -> id;
883 unsafe fn URLWithDataRepresentation_relativeToURL_(
884 _: Self,
885 data: id, url: id,
887 ) -> id;
888 unsafe fn initWithDataRepresentation_relativeToURL_(
889 self,
890 data: id, url: id,
892 ) -> id;
893 unsafe fn dataRepresentation(self) -> id ;
894
895 unsafe fn isEqual_(self, id: id) -> BOOL;
896
897 unsafe fn checkResourceIsReachableAndReturnError_(
898 self,
899 error: id, ) -> BOOL;
901 unsafe fn isFileReferenceURL(self) -> BOOL;
902 unsafe fn isFileURL(self) -> BOOL;
903
904 unsafe fn absoluteString(self) -> id ;
905 unsafe fn absoluteURL(self) -> id ;
906 unsafe fn baseURL(self) -> id ;
907 unsafe fn fragment(self) -> id ;
909 unsafe fn host(self) -> id ;
910 unsafe fn lastPathComponent(self) -> id ;
911 unsafe fn parameterString(self) -> id ;
912 unsafe fn password(self) -> id ;
913 unsafe fn path(self) -> id ;
914 unsafe fn pathComponents(self) -> id ;
915 unsafe fn pathExtension(self) -> id ;
916 unsafe fn port(self) -> id ;
917 unsafe fn query(self) -> id ;
918 unsafe fn relativePath(self) -> id ;
919 unsafe fn relativeString(self) -> id ;
920 unsafe fn resourceSpecifier(self) -> id ;
921 unsafe fn scheme(self) -> id ;
922 unsafe fn standardizedURL(self) -> id ;
923 unsafe fn user(self) -> id ;
924
925 unsafe fn NSURLResourceKey(self) -> id ;
933
934 unsafe fn filePathURL(self) -> id;
935 unsafe fn fileReferenceURL(self) -> id;
936 unsafe fn URLByAppendingPathComponent_(self, path_component: id ) -> id;
937 unsafe fn URLByAppendingPathComponent_isDirectory_(
938 self,
939 path_component: id, is_dir: BOOL,
941 ) -> id;
942 unsafe fn URLByAppendingPathExtension_(self, extension: id ) -> id;
943 unsafe fn URLByDeletingLastPathComponent(self) -> id;
944 unsafe fn URLByDeletingPathExtension(self) -> id;
945 unsafe fn URLByResolvingSymlinksInPath(self) -> id;
946 unsafe fn URLByStandardizingPath(self) -> id;
947 unsafe fn hasDirectoryPath(self) -> BOOL;
948
949 unsafe fn bookmarkDataWithContentsOfURL_error_(
950 _: Self,
951 url: id,
952 error: id, ) -> id ;
954 unsafe fn bookmarkDataWithOptions_includingResourceValuesForKeys_relativeToURL_error_(
955 self,
956 options: NSURLBookmarkCreationOptions,
957 resource_value_for_keys: id, relative_to_url: id,
959 error: id, ) -> id ;
961 unsafe fn writeBookmarkData_toURL_options_error_(
963 _: Self,
964 data: id, to_url: id,
966 options: NSURLBookmarkFileCreationOptions,
967 error: id, ) -> id;
969 unsafe fn startAccessingSecurityScopedResource(self) -> BOOL;
970 unsafe fn stopAccessingSecurityScopedResource(self);
971 unsafe fn NSURLBookmarkFileCreationOptions(self) -> NSURLBookmarkFileCreationOptions;
972 unsafe fn NSURLBookmarkCreationOptions(self) -> NSURLBookmarkCreationOptions;
973 unsafe fn NSURLBookmarkResolutionOptions(self) -> NSURLBookmarkResolutionOptions;
974
975 }
982
983impl NSURL for id {
984 unsafe fn alloc(_: Self) -> id {
985 msg_send![class!(NSURL), alloc]
986 }
987
988 unsafe fn URLWithString_(_: Self, string: id) -> id {
989 msg_send![class!(NSURL), URLWithString: string]
990 }
991 unsafe fn initWithString_(self, string: id) -> id {
992 msg_send![self, initWithString: string]
993 }
994 unsafe fn URLWithString_relativeToURL_(_: Self, string: id, url: id) -> id {
995 msg_send![class!(NSURL), URLWithString: string relativeToURL:url]
996 }
997 unsafe fn initWithString_relativeToURL_(self, string: id, url: id) -> id {
998 msg_send![self, initWithString:string relativeToURL:url]
999 }
1000 unsafe fn fileURLWithPath_isDirectory_(_: Self, path: id, is_dir: BOOL) -> id {
1001 msg_send![class!(NSURL), fileURLWithPath:path isDirectory:is_dir]
1002 }
1003 unsafe fn initFileURLWithPath_isDirectory_(self, path: id, is_dir: BOOL) -> id {
1004 msg_send![self, initFileURLWithPath:path isDirectory:is_dir]
1005 }
1006 unsafe fn fileURLWithPath_relativeToURL_(_: Self, path: id, url: id) -> id {
1007 msg_send![class!(NSURL), fileURLWithPath:path relativeToURL:url]
1008 }
1009 unsafe fn initFileURLWithPath_relativeToURL_(self, path: id, url: id) -> id {
1010 msg_send![self, initFileURLWithPath:path relativeToURL:url]
1011 }
1012 unsafe fn fileURLWithPath_isDirectory_relativeToURL_(
1013 _: Self,
1014 path: id,
1015 is_dir: BOOL,
1016 url: id,
1017 ) -> id {
1018 msg_send![class!(NSURL), fileURLWithPath:path isDirectory:is_dir relativeToURL:url]
1019 }
1020 unsafe fn initFileURLWithPath_isDirectory_relativeToURL_(
1021 self,
1022 path: id,
1023 is_dir: BOOL,
1024 url: id,
1025 ) -> id {
1026 msg_send![self, initFileURLWithPath:path isDirectory:is_dir relativeToURL:url]
1027 }
1028 unsafe fn fileURLWithPath_(_: Self, path: id) -> id {
1029 msg_send![class!(NSURL), fileURLWithPath: path]
1030 }
1031 unsafe fn initFileURLWithPath_(self, path: id) -> id {
1032 msg_send![self, initFileURLWithPath: path]
1033 }
1034 unsafe fn fileURLWithPathComponents_(
1035 _: Self,
1036 path_components: id, ) -> id {
1038 msg_send![class!(NSURL), fileURLWithPathComponents: path_components]
1039 }
1040 unsafe fn URLByResolvingAliasFileAtURL_options_error_(
1041 _: Self,
1042 url: id,
1043 options: NSURLBookmarkResolutionOptions,
1044 error: *mut id, ) -> id {
1046 msg_send![class!(NSURL), URLByResolvingAliasFileAtURL:url options:options error:error]
1047 }
1048 unsafe fn URLByResolvingBookmarkData_options_relativeToURL_bookmarkDataIsStale_error_(
1049 _: Self,
1050 data: id, options: NSURLBookmarkResolutionOptions,
1052 relative_to_url: id,
1053 is_stale: *mut BOOL,
1054 error: *mut id, ) -> id {
1056 msg_send![class!(NSURL), URLByResolvingBookmarkData:data options:options relativeToURL:relative_to_url bookmarkDataIsStale:is_stale error:error]
1057 }
1058 unsafe fn initByResolvingBookmarkData_options_relativeToURL_bookmarkDataIsStale_error_(
1059 self,
1060 data: id, options: NSURLBookmarkResolutionOptions,
1062 relative_to_url: id,
1063 is_stale: *mut BOOL,
1064 error: *mut id, ) -> id {
1066 msg_send![self, initByResolvingBookmarkData:data options:options relativeToURL:relative_to_url bookmarkDataIsStale:is_stale error:error]
1067 }
1068 unsafe fn absoluteURLWithDataRepresentation_relativeToURL_(
1072 _: Self,
1073 data: id, url: id,
1075 ) -> id {
1076 msg_send![class!(NSURL), absoluteURLWithDataRepresentation:data relativeToURL:url]
1077 }
1078 unsafe fn initAbsoluteURLWithDataRepresentation_relativeToURL_(
1079 self,
1080 data: id, url: id,
1082 ) -> id {
1083 msg_send![self, initAbsoluteURLWithDataRepresentation:data relativeToURL:url]
1084 }
1085 unsafe fn URLWithDataRepresentation_relativeToURL_(
1086 _: Self,
1087 data: id, url: id,
1089 ) -> id {
1090 msg_send![class!(NSURL), URLWithDataRepresentation:data relativeToURL:url]
1091 }
1092 unsafe fn initWithDataRepresentation_relativeToURL_(
1093 self,
1094 data: id, url: id,
1096 ) -> id {
1097 msg_send![self, initWithDataRepresentation:data relativeToURL:url]
1098 }
1099 unsafe fn dataRepresentation(self) -> id {
1100 msg_send![self, dataRepresentation]
1101 }
1102
1103 unsafe fn isEqual_(self, id: id) -> BOOL {
1104 msg_send![self, isEqual: id]
1105 }
1106
1107 unsafe fn checkResourceIsReachableAndReturnError_(
1108 self,
1109 error: id, ) -> BOOL {
1111 msg_send![self, checkResourceIsReachableAndReturnError: error]
1112 }
1113 unsafe fn isFileReferenceURL(self) -> BOOL {
1114 msg_send![self, isFileReferenceURL]
1115 }
1116 unsafe fn isFileURL(self) -> BOOL {
1117 msg_send![self, isFileURL]
1118 }
1119
1120 unsafe fn absoluteString(self) -> id {
1121 msg_send![self, absoluteString]
1122 }
1123 unsafe fn absoluteURL(self) -> id {
1124 msg_send![self, absoluteURL]
1125 }
1126 unsafe fn baseURL(self) -> id {
1127 msg_send![self, baseURL]
1128 }
1129 unsafe fn fragment(self) -> id {
1131 msg_send![self, fragment]
1132 }
1133 unsafe fn host(self) -> id {
1134 msg_send![self, host]
1135 }
1136 unsafe fn lastPathComponent(self) -> id {
1137 msg_send![self, lastPathComponent]
1138 }
1139 unsafe fn parameterString(self) -> id {
1140 msg_send![self, parameterString]
1141 }
1142 unsafe fn password(self) -> id {
1143 msg_send![self, password]
1144 }
1145 unsafe fn path(self) -> id {
1146 msg_send![self, path]
1147 }
1148 unsafe fn pathComponents(self) -> id {
1149 msg_send![self, pathComponents]
1150 }
1151 unsafe fn pathExtension(self) -> id {
1152 msg_send![self, pathExtension]
1153 }
1154 unsafe fn port(self) -> id {
1155 msg_send![self, port]
1156 }
1157 unsafe fn query(self) -> id {
1158 msg_send![self, query]
1159 }
1160 unsafe fn relativePath(self) -> id {
1161 msg_send![self, relativePath]
1162 }
1163 unsafe fn relativeString(self) -> id {
1164 msg_send![self, relativeString]
1165 }
1166 unsafe fn resourceSpecifier(self) -> id {
1167 msg_send![self, resourceSpecifier]
1168 }
1169 unsafe fn scheme(self) -> id {
1170 msg_send![self, scheme]
1171 }
1172 unsafe fn standardizedURL(self) -> id {
1173 msg_send![self, standardizedURL]
1174 }
1175 unsafe fn user(self) -> id {
1176 msg_send![self, user]
1177 }
1178
1179 unsafe fn NSURLResourceKey(self) -> id {
1187 msg_send![self, NSURLResourceKey]
1188 }
1189
1190 unsafe fn filePathURL(self) -> id {
1191 msg_send![self, filePathURL]
1192 }
1193 unsafe fn fileReferenceURL(self) -> id {
1194 msg_send![self, fileReferenceURL]
1195 }
1196 unsafe fn URLByAppendingPathComponent_(self, path_component: id ) -> id {
1197 msg_send![self, URLByAppendingPathComponent: path_component]
1198 }
1199 unsafe fn URLByAppendingPathComponent_isDirectory_(
1200 self,
1201 path_component: id, is_dir: BOOL,
1203 ) -> id {
1204 msg_send![self, URLByAppendingPathComponent:path_component isDirectory:is_dir]
1205 }
1206 unsafe fn URLByAppendingPathExtension_(self, extension: id ) -> id {
1207 msg_send![self, URLByAppendingPathExtension: extension]
1208 }
1209 unsafe fn URLByDeletingLastPathComponent(self) -> id {
1210 msg_send![self, URLByDeletingLastPathComponent]
1211 }
1212 unsafe fn URLByDeletingPathExtension(self) -> id {
1213 msg_send![self, URLByDeletingPathExtension]
1214 }
1215 unsafe fn URLByResolvingSymlinksInPath(self) -> id {
1216 msg_send![self, URLByResolvingSymlinksInPath]
1217 }
1218 unsafe fn URLByStandardizingPath(self) -> id {
1219 msg_send![self, URLByStandardizingPath]
1220 }
1221 unsafe fn hasDirectoryPath(self) -> BOOL {
1222 msg_send![self, hasDirectoryPath]
1223 }
1224
1225 unsafe fn bookmarkDataWithContentsOfURL_error_(
1226 _: Self,
1227 url: id,
1228 error: id, ) -> id {
1230 msg_send![class!(NSURL), bookmarkDataWithContentsOfURL:url error:error]
1231 }
1232 unsafe fn bookmarkDataWithOptions_includingResourceValuesForKeys_relativeToURL_error_(
1233 self,
1234 options: NSURLBookmarkCreationOptions,
1235 resource_value_for_keys: id, relative_to_url: id,
1237 error: id, ) -> id {
1239 msg_send![self, bookmarkDataWithOptions:options includingResourceValuesForKeys:resource_value_for_keys relativeToURL:relative_to_url error:error]
1240 }
1241 unsafe fn writeBookmarkData_toURL_options_error_(
1243 _: Self,
1244 data: id, to_url: id,
1246 options: NSURLBookmarkFileCreationOptions,
1247 error: id, ) -> id {
1249 msg_send![class!(NSURL), writeBookmarkData:data toURL:to_url options:options error:error]
1250 }
1251 unsafe fn startAccessingSecurityScopedResource(self) -> BOOL {
1252 msg_send![self, startAccessingSecurityScopedResource]
1253 }
1254 unsafe fn stopAccessingSecurityScopedResource(self) {
1255 msg_send![self, stopAccessingSecurityScopedResource]
1256 }
1257 unsafe fn NSURLBookmarkFileCreationOptions(self) -> NSURLBookmarkFileCreationOptions {
1258 msg_send![self, NSURLBookmarkFileCreationOptions]
1259 }
1260 unsafe fn NSURLBookmarkCreationOptions(self) -> NSURLBookmarkCreationOptions {
1261 msg_send![self, NSURLBookmarkCreationOptions]
1262 }
1263 unsafe fn NSURLBookmarkResolutionOptions(self) -> NSURLBookmarkResolutionOptions {
1264 msg_send![self, NSURLBookmarkResolutionOptions]
1265 }
1266
1267 }
1274
1275pub trait NSBundle: Sized {
1276 unsafe fn mainBundle() -> Self;
1277
1278 unsafe fn loadNibNamed_owner_topLevelObjects_(
1279 self,
1280 name: id, owner: id,
1282 topLevelObjects: *mut id, ) -> BOOL;
1284
1285 unsafe fn bundleIdentifier(self) -> id ;
1286
1287 unsafe fn resourcePath(self) -> id ;
1288}
1289
1290impl NSBundle for id {
1291 unsafe fn mainBundle() -> id {
1292 msg_send![class!(NSBundle), mainBundle]
1293 }
1294
1295 unsafe fn loadNibNamed_owner_topLevelObjects_(
1296 self,
1297 name: id, owner: id,
1299 topLevelObjects: *mut id, ) -> BOOL {
1301 msg_send![self, loadNibNamed:name
1302 owner:owner
1303 topLevelObjects:topLevelObjects]
1304 }
1305
1306 unsafe fn bundleIdentifier(self) -> id {
1307 msg_send![self, bundleIdentifier]
1308 }
1309
1310 unsafe fn resourcePath(self) -> id {
1311 msg_send![self, resourcePath]
1312 }
1313}
1314
1315pub trait NSData: Sized {
1316 unsafe fn data(_: Self) -> id {
1317 msg_send![class!(NSData), data]
1318 }
1319
1320 unsafe fn dataWithBytes_length_(_: Self, bytes: *const c_void, length: NSUInteger) -> id {
1321 msg_send![class!(NSData), dataWithBytes:bytes length:length]
1322 }
1323
1324 unsafe fn dataWithBytesNoCopy_length_(_: Self, bytes: *const c_void, length: NSUInteger) -> id {
1325 msg_send![class!(NSData), dataWithBytesNoCopy:bytes length:length]
1326 }
1327
1328 unsafe fn dataWithBytesNoCopy_length_freeWhenDone_(
1329 _: Self,
1330 bytes: *const c_void,
1331 length: NSUInteger,
1332 freeWhenDone: BOOL,
1333 ) -> id {
1334 msg_send![class!(NSData), dataWithBytesNoCopy:bytes length:length freeWhenDone:freeWhenDone]
1335 }
1336
1337 unsafe fn dataWithContentsOfFile_(_: Self, path: id) -> id {
1338 msg_send![class!(NSData), dataWithContentsOfFile: path]
1339 }
1340
1341 unsafe fn dataWithContentsOfFile_options_error_(
1342 _: Self,
1343 path: id,
1344 mask: NSDataReadingOptions,
1345 errorPtr: *mut id,
1346 ) -> id {
1347 msg_send![class!(NSData), dataWithContentsOfFile:path options:mask error:errorPtr]
1348 }
1349
1350 unsafe fn dataWithContentsOfURL_(_: Self, aURL: id) -> id {
1351 msg_send![class!(NSData), dataWithContentsOfURL: aURL]
1352 }
1353
1354 unsafe fn dataWithContentsOfURL_options_error_(
1355 _: Self,
1356 aURL: id,
1357 mask: NSDataReadingOptions,
1358 errorPtr: *mut id,
1359 ) -> id {
1360 msg_send![class!(NSData), dataWithContentsOfURL:aURL options:mask error:errorPtr]
1361 }
1362
1363 unsafe fn dataWithData_(_: Self, aData: id) -> id {
1364 msg_send![class!(NSData), dataWithData: aData]
1365 }
1366
1367 unsafe fn initWithBase64EncodedData_options_(
1368 self,
1369 base64Data: id,
1370 options: NSDataBase64DecodingOptions,
1371 ) -> id;
1372 unsafe fn initWithBase64EncodedString_options_(
1373 self,
1374 base64String: id,
1375 options: NSDataBase64DecodingOptions,
1376 ) -> id;
1377 unsafe fn initWithBytes_length_(self, bytes: *const c_void, length: NSUInteger) -> id;
1378 unsafe fn initWithBytesNoCopy_length_(self, bytes: *const c_void, length: NSUInteger) -> id;
1379 unsafe fn initWithBytesNoCopy_length_deallocator_(
1380 self,
1381 bytes: *const c_void,
1382 length: NSUInteger,
1383 deallocator: *mut Block<(*const c_void, NSUInteger), ()>,
1384 ) -> id;
1385 unsafe fn initWithBytesNoCopy_length_freeWhenDone_(
1386 self,
1387 bytes: *const c_void,
1388 length: NSUInteger,
1389 freeWhenDone: BOOL,
1390 ) -> id;
1391 unsafe fn initWithContentsOfFile_(self, path: id) -> id;
1392 unsafe fn initWithContentsOfFile_options_error(
1393 self,
1394 path: id,
1395 mask: NSDataReadingOptions,
1396 errorPtr: *mut id,
1397 ) -> id;
1398 unsafe fn initWithContentsOfURL_(self, aURL: id) -> id;
1399 unsafe fn initWithContentsOfURL_options_error_(
1400 self,
1401 aURL: id,
1402 mask: NSDataReadingOptions,
1403 errorPtr: *mut id,
1404 ) -> id;
1405 unsafe fn initWithData_(self, data: id) -> id;
1406
1407 unsafe fn bytes(self) -> *const c_void;
1408 unsafe fn description(self) -> id;
1409 unsafe fn enumerateByteRangesUsingBlock_(
1410 self,
1411 block: *mut Block<(*const c_void, NSRange, *mut BOOL), ()>,
1412 );
1413 unsafe fn getBytes_length_(self, buffer: *mut c_void, length: NSUInteger);
1414 unsafe fn getBytes_range_(self, buffer: *mut c_void, range: NSRange);
1415 unsafe fn subdataWithRange_(self, range: NSRange) -> id;
1416 unsafe fn rangeOfData_options_range_(
1417 self,
1418 dataToFind: id,
1419 options: NSDataSearchOptions,
1420 searchRange: NSRange,
1421 ) -> NSRange;
1422
1423 unsafe fn base64EncodedDataWithOptions_(self, options: NSDataBase64EncodingOptions) -> id;
1424 unsafe fn base64EncodedStringWithOptions_(self, options: NSDataBase64EncodingOptions) -> id;
1425
1426 unsafe fn isEqualToData_(self, otherData: id) -> id;
1427 unsafe fn length(self) -> NSUInteger;
1428
1429 unsafe fn writeToFile_atomically_(self, path: id, atomically: BOOL) -> BOOL;
1430 unsafe fn writeToFile_options_error_(
1431 self,
1432 path: id,
1433 mask: NSDataWritingOptions,
1434 errorPtr: *mut id,
1435 ) -> BOOL;
1436 unsafe fn writeToURL_atomically_(self, aURL: id, atomically: BOOL) -> BOOL;
1437 unsafe fn writeToURL_options_error_(
1438 self,
1439 aURL: id,
1440 mask: NSDataWritingOptions,
1441 errorPtr: *mut id,
1442 ) -> BOOL;
1443}
1444
1445impl NSData for id {
1446 unsafe fn initWithBase64EncodedData_options_(
1447 self,
1448 base64Data: id,
1449 options: NSDataBase64DecodingOptions,
1450 ) -> id {
1451 msg_send![self, initWithBase64EncodedData:base64Data options:options]
1452 }
1453
1454 unsafe fn initWithBase64EncodedString_options_(
1455 self,
1456 base64String: id,
1457 options: NSDataBase64DecodingOptions,
1458 ) -> id {
1459 msg_send![self, initWithBase64EncodedString:base64String options:options]
1460 }
1461
1462 unsafe fn initWithBytes_length_(self, bytes: *const c_void, length: NSUInteger) -> id {
1463 msg_send![self,initWithBytes:bytes length:length]
1464 }
1465
1466 unsafe fn initWithBytesNoCopy_length_(self, bytes: *const c_void, length: NSUInteger) -> id {
1467 msg_send![self, initWithBytesNoCopy:bytes length:length]
1468 }
1469
1470 unsafe fn initWithBytesNoCopy_length_deallocator_(
1471 self,
1472 bytes: *const c_void,
1473 length: NSUInteger,
1474 deallocator: *mut Block<(*const c_void, NSUInteger), ()>,
1475 ) -> id {
1476 msg_send![self, initWithBytesNoCopy:bytes length:length deallocator:deallocator]
1477 }
1478
1479 unsafe fn initWithBytesNoCopy_length_freeWhenDone_(
1480 self,
1481 bytes: *const c_void,
1482 length: NSUInteger,
1483 freeWhenDone: BOOL,
1484 ) -> id {
1485 msg_send![self, initWithBytesNoCopy:bytes length:length freeWhenDone:freeWhenDone]
1486 }
1487
1488 unsafe fn initWithContentsOfFile_(self, path: id) -> id {
1489 msg_send![self, initWithContentsOfFile: path]
1490 }
1491
1492 unsafe fn initWithContentsOfFile_options_error(
1493 self,
1494 path: id,
1495 mask: NSDataReadingOptions,
1496 errorPtr: *mut id,
1497 ) -> id {
1498 msg_send![self, initWithContentsOfFile:path options:mask error:errorPtr]
1499 }
1500
1501 unsafe fn initWithContentsOfURL_(self, aURL: id) -> id {
1502 msg_send![self, initWithContentsOfURL: aURL]
1503 }
1504
1505 unsafe fn initWithContentsOfURL_options_error_(
1506 self,
1507 aURL: id,
1508 mask: NSDataReadingOptions,
1509 errorPtr: *mut id,
1510 ) -> id {
1511 msg_send![self, initWithContentsOfURL:aURL options:mask error:errorPtr]
1512 }
1513
1514 unsafe fn initWithData_(self, data: id) -> id {
1515 msg_send![self, initWithData: data]
1516 }
1517
1518 unsafe fn bytes(self) -> *const c_void {
1519 msg_send![self, bytes]
1520 }
1521
1522 unsafe fn description(self) -> id {
1523 msg_send![self, description]
1524 }
1525
1526 unsafe fn enumerateByteRangesUsingBlock_(
1527 self,
1528 block: *mut Block<(*const c_void, NSRange, *mut BOOL), ()>,
1529 ) {
1530 msg_send![self, enumerateByteRangesUsingBlock: block]
1531 }
1532
1533 unsafe fn getBytes_length_(self, buffer: *mut c_void, length: NSUInteger) {
1534 msg_send![self, getBytes:buffer length:length]
1535 }
1536
1537 unsafe fn getBytes_range_(self, buffer: *mut c_void, range: NSRange) {
1538 msg_send![self, getBytes:buffer range:range]
1539 }
1540
1541 unsafe fn subdataWithRange_(self, range: NSRange) -> id {
1542 msg_send![self, subdataWithRange: range]
1543 }
1544
1545 unsafe fn rangeOfData_options_range_(
1546 self,
1547 dataToFind: id,
1548 options: NSDataSearchOptions,
1549 searchRange: NSRange,
1550 ) -> NSRange {
1551 msg_send![self, rangeOfData:dataToFind options:options range:searchRange]
1552 }
1553
1554 unsafe fn base64EncodedDataWithOptions_(self, options: NSDataBase64EncodingOptions) -> id {
1555 msg_send![self, base64EncodedDataWithOptions: options]
1556 }
1557
1558 unsafe fn base64EncodedStringWithOptions_(self, options: NSDataBase64EncodingOptions) -> id {
1559 msg_send![self, base64EncodedStringWithOptions: options]
1560 }
1561
1562 unsafe fn isEqualToData_(self, otherData: id) -> id {
1563 msg_send![self, isEqualToData: otherData]
1564 }
1565
1566 unsafe fn length(self) -> NSUInteger {
1567 msg_send![self, length]
1568 }
1569
1570 unsafe fn writeToFile_atomically_(self, path: id, atomically: BOOL) -> BOOL {
1571 msg_send![self, writeToFile:path atomically:atomically]
1572 }
1573
1574 unsafe fn writeToFile_options_error_(
1575 self,
1576 path: id,
1577 mask: NSDataWritingOptions,
1578 errorPtr: *mut id,
1579 ) -> BOOL {
1580 msg_send![self, writeToFile:path options:mask error:errorPtr]
1581 }
1582
1583 unsafe fn writeToURL_atomically_(self, aURL: id, atomically: BOOL) -> BOOL {
1584 msg_send![self, writeToURL:aURL atomically:atomically]
1585 }
1586
1587 unsafe fn writeToURL_options_error_(
1588 self,
1589 aURL: id,
1590 mask: NSDataWritingOptions,
1591 errorPtr: *mut id,
1592 ) -> BOOL {
1593 msg_send![self, writeToURL:aURL options:mask error:errorPtr]
1594 }
1595}
1596
1597bitflags! {
1598 #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
1599 pub struct NSDataReadingOptions: libc::c_ulonglong {
1600 const NSDataReadingMappedIfSafe = 1 << 0;
1601 const NSDataReadingUncached = 1 << 1;
1602 const NSDataReadingMappedAlways = 1 << 3;
1603 }
1604}
1605
1606bitflags! {
1607 #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
1608 pub struct NSDataBase64EncodingOptions: libc::c_ulonglong {
1609 const NSDataBase64Encoding64CharacterLineLength = 1 << 0;
1610 const NSDataBase64Encoding76CharacterLineLength = 1 << 1;
1611 const NSDataBase64EncodingEndLineWithCarriageReturn = 1 << 4;
1612 const NSDataBase64EncodingEndLineWithLineFeed = 1 << 5;
1613 }
1614}
1615
1616bitflags! {
1617 #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
1618 pub struct NSDataBase64DecodingOptions: libc::c_ulonglong {
1619 const NSDataBase64DecodingIgnoreUnknownCharacters = 1 << 0;
1620 }
1621}
1622
1623bitflags! {
1624 #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
1625 pub struct NSDataWritingOptions: libc::c_ulonglong {
1626 const NSDataWritingAtomic = 1 << 0;
1627 const NSDataWritingWithoutOverwriting = 1 << 1;
1628 }
1629}
1630
1631bitflags! {
1632 #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
1633 pub struct NSDataSearchOptions: libc::c_ulonglong {
1634 const NSDataSearchBackwards = 1 << 0;
1635 const NSDataSearchAnchored = 1 << 1;
1636 }
1637}
1638
1639pub trait NSUserDefaults {
1640 unsafe fn standardUserDefaults() -> Self;
1641
1642 unsafe fn setBool_forKey_(self, value: BOOL, key: id);
1643 unsafe fn bool_forKey_(self, key: id) -> BOOL;
1644
1645 unsafe fn removeObject_forKey_(self, key: id);
1646}
1647
1648impl NSUserDefaults for id {
1649 unsafe fn standardUserDefaults() -> id {
1650 msg_send![class!(NSUserDefaults), standardUserDefaults]
1651 }
1652
1653 unsafe fn setBool_forKey_(self, value: BOOL, key: id) {
1654 msg_send![self, setBool:value forKey:key]
1655 }
1656
1657 unsafe fn bool_forKey_(self, key: id) -> BOOL {
1658 msg_send![self, boolForKey: key]
1659 }
1660
1661 unsafe fn removeObject_forKey_(self, key: id) {
1662 msg_send![self, removeObjectForKey: key]
1663 }
1664}