-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic version of NSError #16
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
doc/ | ||
target/ | ||
Cargo.lock | ||
.idea | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use objc_id::Id; | ||
use {INSObject, NSInteger, NSDictionary, NSString, INSString}; | ||
|
||
pub type NSErrorUserInfoKey = NSString; | ||
|
||
#[allow(non_snake_case)] | ||
pub fn NSLocalizedDescriptionKey() -> Id<NSString> { | ||
NSString::from_str(&"NSLocalizedDescription") | ||
} | ||
Comment on lines
+6
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An alternative would be to use the In the future something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, this actually has value |
||
|
||
pub trait INSError: INSObject { | ||
fn new<T>(code: NSInteger, domain: Id<NSString>, user_info: Id<NSDictionary<NSErrorUserInfoKey, T>>) -> Id<Self> { | ||
let cls = Self::class(); | ||
unsafe { | ||
let obj: *mut Self = msg_send![cls, alloc]; | ||
let obj: *mut Self = msg_send![obj, initWithDomain:domain | ||
code:code | ||
userInfo:user_info]; | ||
Id::from_retained_ptr(obj) | ||
} | ||
} | ||
} | ||
|
||
object_struct!(NSError); | ||
|
||
impl INSError for NSError {} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub type NSInteger = isize; | ||
pub type NSUInteger = usize; | ||
Comment on lines
+1
to
+2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these could be useful to have in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding this to your
~/.gitignore_global
instead? Unless IntelliJ works differently than how I think it does.