From 9c4b5c9310c142cdcb489de66fcfb6ab58f4d4fc Mon Sep 17 00:00:00 2001 From: Casper Storm Date: Wed, 29 Apr 2020 12:22:51 +0200 Subject: [PATCH] feat: added binding to NSUserDefaults --- cocoa/src/foundation.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/cocoa/src/foundation.rs b/cocoa/src/foundation.rs index d87c446..4d56421 100644 --- a/cocoa/src/foundation.rs +++ b/cocoa/src/foundation.rs @@ -1316,3 +1316,30 @@ bitflags! { const NSDataSearchAnchored = 1 << 1; } } + +pub trait NSUserDefaults { + unsafe fn standardUserDefaults() -> Self; + + unsafe fn setBool_forKey_(self, value: BOOL, key: id); + unsafe fn bool_forKey_(self, key: id) -> BOOL; + + unsafe fn removeObject_forKey_(self, key: id); +} + +impl NSUserDefaults for id { + unsafe fn standardUserDefaults() -> id { + msg_send![class!(NSUserDefaults), standardUserDefaults] + } + + unsafe fn setBool_forKey_(self, value: BOOL, key: id) { + msg_send![self, setBool:value forKey:key] + } + + unsafe fn bool_forKey_(self, key: id) -> BOOL { + msg_send![self, boolForKey: key] + } + + unsafe fn removeObject_forKey_(self, key: id) { + msg_send![self, removeObjectForKey:key] + } +}