zettacode.files/hello_world.text/objective-c.txt in zettacode-0.1.0 vs zettacode.files/hello_world.text/objective-c.txt in zettacode-0.1.1

- old
+ new

@@ -1,42 +1,42 @@ -{{ |c-602.0.53}} +{{works with|clang-602.0.53}} -T fc Objc-C "H, W!" c u f, u NSL() fuc: +The de facto Objective-C "Hello, World!" program is most commonly illustrated as the following, using the NSLog() function: -# FuFu. +#import <Foundation/Foundation.h> - () { - @u { - NSL(@"H, W!") +int main() { + @autoreleasepool { + NSLog(@"Hello, World!"); } } -H u f NSL() fuc f , c c c f "H, W!" f qu uu. +However the purpose of the NSLog() function is to print a message to standard error prefixed with a timestamp, which does not meet the most common criteria of a "Hello, World!" program of displaying only the requested message to standard output. -T f c uu u u cu Objc-C : +The following code prints the message to standard output without a timestamp using exclusively Objective-C messages: -# FuFu. +#import <Foundation/Foundation.h> - () { - @u { - NSFH *Ouu = [NSFH fHWSOuu] - NSS * = @"H, W!\" - [Ouu D:[ UEc:NSUTF8SEc]] +int main() { + @autoreleasepool { + NSFileHandle *standardOutput = [NSFileHandle fileHandleWithStandardOutput]; + NSString *message = @"Hello, World!\n"; + [standardOutput writeData:[message dataUsingEncoding:NSUTF8StringEncoding]]; } } -Objc-C u fuc c C b. H, Objc-C' NSS bjc u b c UTF-8 b u b C u' IO fuc. +Objective-C also supports functions contained within the C standard library. However, Objective-C's NSString objects must be converted into a UTF-8 string in order to be supported by the C language's I/O functions. -# FuFu. +#import <Foundation/Foundation.h> - () { - @u { - NSS * = @"H, W!\" - f("%", .UTF8S) +int main() { + @autoreleasepool { + NSString *message = @"Hello, World!\n"; + printf("%s", message.UTF8String); } }