rust_macios/foundation/
ns_bundle.rs

1use objc::{msg_send, sel, sel_impl};
2
3use crate::{
4    object,
5    objective_c_runtime::{
6        id,
7        macros::interface_impl,
8        traits::{FromId, PNSObject},
9    },
10};
11
12use super::{NSArray, NSDictionary, NSString};
13
14object! {
15    /// A representation of the code and resources stored in a bundle directory on disk.
16    unsafe pub struct NSBundle;
17}
18
19#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
20#[repr(usize)]
21pub enum MachOArchitecture {
22    ARM64 = 0x0100000c,
23    I386 = 0x00000007,
24    X86_64 = 0x01000007,
25    PPC = 0x00000012,
26    PPC64 = 0x01000012,
27}
28
29#[interface_impl(NSObject)]
30impl NSBundle {
31    /* Getting Standard Bundle Objects */
32
33    /// Returns the bundle object that contains the current executable.
34    #[property]
35    pub fn main_bundle() -> NSBundle {
36        unsafe { NSBundle::from_id(msg_send![Self::m_class(), mainBundle]) }
37    }
38
39    /// Returns an array of all of the application’s bundles that represent frameworks.
40    #[property]
41    pub fn all_frameworks() -> NSArray<NSBundle> {
42        unsafe { NSArray::from_id(msg_send![Self::m_class(), allFrameworks]) }
43    }
44
45    /// Returns an array of all the application’s non-framework bundles.
46    #[property]
47    pub fn all_bundles() -> NSArray<NSBundle> {
48        unsafe { NSArray::from_id(msg_send![Self::m_class(), allBundles]) }
49    }
50
51    /// The full pathname of the bundle’s subdirectory containing resources.
52    #[property]
53    pub fn resource_path(&self) -> NSString {
54        unsafe { NSString::from_id(msg_send![self.m_self(), resourcePath]) }
55    }
56
57    /// The full pathname of the receiver's executable file.
58    #[property]
59    pub fn executable_path(&self) -> NSString {
60        unsafe { NSString::from_id(msg_send![self.m_self(), executablePath]) }
61    }
62
63    /// The full pathname of the receiver’s bundle directory.
64    #[property]
65    pub fn bundle_path(&self) -> NSString {
66        unsafe { NSString::from_id(msg_send![self.m_self(), bundlePath]) }
67    }
68
69    /// The receiver’s bundle identifier.
70    #[property]
71    pub fn bundle_identifier(&self) -> NSString {
72        unsafe { NSString::from_id(msg_send![self.m_self(), bundleIdentifier]) }
73    }
74
75    /// A dictionary, constructed from the bundle’s Info.plist file, that contains information about the receiver.
76    #[property]
77    pub fn info_dictionary(&self) -> NSDictionary<NSString, id> {
78        unsafe { NSDictionary::from_id(msg_send![self.m_self(), infoDictionary]) }
79    }
80}