1+ #[ cfg( all( feature = "apple" , target_os = "macos" ) ) ]
12use objc2:: {
23 msg_send, msg_send_id,
34 rc:: { Id , Shared } ,
45 runtime:: { Bool , Object } ,
56} ;
7+ #[ cfg( all( feature = "apple" , target_os = "macos" ) ) ]
68use objc2_foundation:: { declare_class, extern_class, NSObject } ;
79
810#[ cfg( all( feature = "apple" , target_os = "macos" ) ) ]
911#[ link( name = "AppKit" , kind = "framework" ) ]
1012extern "C" { }
1113
14+ #[ cfg( all( feature = "apple" , target_os = "macos" ) ) ]
1215extern_class ! {
1316 unsafe struct NSResponder : NSObject ;
1417}
1518
19+ #[ cfg( all( feature = "apple" , target_os = "macos" ) ) ]
1620declare_class ! {
1721 unsafe struct CustomAppDelegate : NSResponder , NSObject {
1822 pub ivar: u8 ,
@@ -66,6 +70,7 @@ declare_class! {
6670 }
6771}
6872
73+ #[ cfg( all( feature = "apple" , target_os = "macos" ) ) ]
6974impl CustomAppDelegate {
7075 pub fn new ( ivar : u8 , another_ivar : bool ) -> Id < Self , Shared > {
7176 let cls = Self :: class ( ) ;
@@ -80,9 +85,15 @@ impl CustomAppDelegate {
8085 }
8186}
8287
88+ #[ cfg( all( feature = "apple" , target_os = "macos" ) ) ]
8389fn main ( ) {
8490 let delegate = CustomAppDelegate :: new ( 42 , true ) ;
8591
8692 println ! ( "{}" , delegate. ivar) ;
8793 println ! ( "{}" , delegate. another_ivar. as_bool( ) ) ;
8894}
95+
96+ #[ cfg( not( all( feature = "apple" , target_os = "macos" ) ) ) ]
97+ fn main ( ) {
98+ panic ! ( "This example uses AppKit, which is only present on macOS" ) ;
99+ }
0 commit comments