@@ -11,42 +11,21 @@ fn main() {
1111
1212#[ cfg( talk_to_me_example) ]
1313fn main ( ) {
14- use objc2:: ffi:: NSUInteger ;
15- use objc2:: rc:: { Id , Owned , Shared } ;
14+ use objc2:: rc:: { Id , Owned } ;
1615 use objc2:: runtime:: Object ;
17- use objc2:: { class, msg_send, msg_send_bool, msg_send_id} ;
18- use std:: ffi:: c_void;
16+ use objc2:: { class, msg_send, msg_send_bool, msg_send_id, ns_string} ;
1917
20- #[ cfg( feature = "apple" ) ]
2118 #[ link( name = "AVFoundation" , kind = "framework" ) ]
2219 extern "C" { }
23- #[ cfg( feature = "apple" ) ]
24- #[ link( name = "Foundation" , kind = "framework" ) ]
25- extern "C" { }
26-
27- const UTF8_ENCODING : NSUInteger = 4 ;
2820
29- let text = "Hello from Rust!" ;
30-
31- // Note: objc2-foundation has functionality to do this safely!
32- let string = unsafe { msg_send_id ! [ class!( NSString ) , alloc] } ;
33- let text_ptr: * const c_void = text. as_ptr ( ) . cast ( ) ;
34- let string: Id < Object , Shared > = unsafe {
35- msg_send_id ! [
36- string,
37- initWithBytes: text_ptr,
38- length: text. len( ) ,
39- encoding: UTF8_ENCODING ,
40- ]
41- }
42- . unwrap ( ) ;
21+ let string = ns_string ! ( "Hello from Rust!" ) ;
4322
4423 let synthesizer: Id < Object , Owned > =
4524 unsafe { msg_send_id ! [ class!( AVSpeechSynthesizer ) , new] } . unwrap ( ) ;
4625
4726 let utterance = unsafe { msg_send_id ! [ class!( AVSpeechUtterance ) , alloc] } ;
4827 let utterance: Id < Object , Owned > =
49- unsafe { msg_send_id ! [ utterance, initWithString: & * string] } . unwrap ( ) ;
28+ unsafe { msg_send_id ! [ utterance, initWithString: string] } . unwrap ( ) ;
5029
5130 // let _: () = unsafe { msg_send![&utterance, setVolume: 90.0f32 };
5231 // let _: () = unsafe { msg_send![&utterance, setRate: 0.50f32 };
0 commit comments