Skip to content

Small fixes #273

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

Merged
merged 4 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions objc2/src/foundation/__ns_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
//! generating a pure `NSString`. We don't support that yet (since I don't
//! know the use-case), but we definitely could!
//! See: <https://github.com/llvm/llvm-project/blob/release/13.x/clang/lib/CodeGen/CGObjCMac.cpp#L2007-L2068>
//!
//! See also the following crates that implement UTF-16 conversion:
//! `utf16_lit`, `windows`, `const_utf16`, `wide-literals`, ...
use core::ffi::c_void;
use core::mem::ManuallyDrop;
use core::ptr;
Expand Down Expand Up @@ -238,6 +241,12 @@ impl CachedNSString {

/// Creates an [`NSString`][`crate::foundation::NSString`] from a static string.
///
/// Note: This works by placing statics in special sections, which may not
/// work completely reliably yet, see [#258]; until then, you should be
/// careful about using this in libraries intended for others to consume.
///
/// [#258]: https://github.com/madsmtm/objc2/issues/258
///
///
/// # Examples
///
Expand Down
19 changes: 11 additions & 8 deletions objc2/src/foundation/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::panic::{RefUnwindSafe, UnwindSafe};

use super::{NSCopying, NSDictionary, NSObject, NSString};
use crate::rc::{Id, Shared};
use crate::{extern_class, extern_methods, msg_send_id, ns_string, ClassType};
use crate::{extern_class, extern_methods, msg_send_id, ClassType};

extern_class!(
/// A representation of the code and resources stored in a bundle
Expand Down Expand Up @@ -36,13 +36,16 @@ extern_methods!(
}

pub fn name(&self) -> Option<Id<NSString, Shared>> {
self.info().get(ns_string!("CFBundleName")).map(|name| {
let ptr: *const NSObject = name;
let ptr: *const NSString = ptr.cast();
// SAFETY: TODO
let name = unsafe { ptr.as_ref().unwrap_unchecked() };
name.copy()
})
// TODO: Use ns_string!
self.info()
.get(&NSString::from_str("CFBundleName"))
.map(|name| {
let ptr: *const NSObject = name;
let ptr: *const NSString = ptr.cast();
// SAFETY: TODO
let name = unsafe { ptr.as_ref().unwrap_unchecked() };
name.copy()
})
}
}
);
Expand Down
Loading