use objc::{msg_send, sel, sel_impl};
use crate::{object,
objective_c_runtime::{
id,
macros::{interface_impl},
traits::{FromId, PNSObject},
},
utils::to_bool,
};
use super::{Int, NSArray, NSDictionary, NSErrorDomain, NSErrorUserInfoKey, NSString, UInt};
object! {
unsafe pub struct NSError;
}
#[interface_impl(NSObject)]
impl NSError {
#[method]
pub fn error_with_domain_code_user_info(
domain: NSErrorDomain,
code: Int,
dict: NSDictionary<NSErrorUserInfoKey, id>,
) -> Self
where
Self: Sized + FromId,
{
unsafe {
Self::from_id(
msg_send![Self::m_class(), errorWithDomain: domain code: code userInfo: dict],
)
}
}
#[method]
pub fn init_with_domain_code_user_info(
&mut self,
domain: NSErrorDomain,
code: Int,
dict: NSDictionary<NSErrorUserInfoKey, id>,
) -> Self
where
Self: Sized + FromId,
{
unsafe {
Self::from_id(
msg_send![self.m_self(), initWithDomain: domain code: code userInfo: dict],
)
}
}
#[property]
pub fn code(&self) -> Int {
unsafe { msg_send![self.m_self(), code] }
}
#[property]
pub fn domain(&self) -> NSErrorDomain {
unsafe { msg_send![self.m_self(), domain] }
}
#[property]
pub fn user_info(&self) -> NSDictionary<NSErrorUserInfoKey, id> {
unsafe { NSDictionary::from_id(msg_send![self.m_self(), userInfo]) }
}
#[property]
pub fn localized_description(&self) -> NSString {
unsafe { NSString::from_id(msg_send![self.m_self(), localizedDescription]) }
}
#[property]
pub fn localized_recovery_options(&self) -> NSArray<NSString> {
unsafe { NSArray::from_id(msg_send![self.m_self(), localizedRecoveryOptions]) }
}
#[property]
pub fn localized_recovery_suggestion(&self) -> NSString {
unsafe { NSString::from_id(msg_send![self.m_self(), localizedRecoverySuggestion]) }
}
#[property]
pub fn localized_failure_reason(&self) -> NSString {
unsafe { NSString::from_id(msg_send![self.m_self(), localizedFailureReason]) }
}
#[property]
pub fn recovery_attempter(&self) -> id {
unsafe { msg_send![self.m_self(), recoveryAttempter] }
}
#[method]
pub fn attempt_recovery_from_error_option_index(
&self,
error: NSError,
recovery_index: UInt,
) -> bool {
unsafe {
to_bool(
msg_send![self.m_self(), attemptRecoveryFromError: error optionIndex: recovery_index],
)
}
}
#[method]
pub fn help_anchor(&self) -> NSString {
unsafe { NSString::from_id(msg_send![self.m_self(), helpAnchor]) }
}
#[property]
pub fn underlying_errors(&self) -> NSArray<NSError> {
unsafe { NSArray::from_id(msg_send![self.m_self(), underlyingErrors]) }
}
}