Sha256: 57789e9df9d2bb6ff9d37c08f33372d3dc4202bc5966256fa07e914517758d9e
Contents?: true
Size: 1.29 KB
Versions: 10
Compression:
Stored size: 1.29 KB
Contents
{{works with|clang-602.0.53}} The de facto Objective-C "Hello, World!" program is most commonly illustrated as the following, using the NSLog() function: #import <Foundation/Foundation.h> int main() { @autoreleasepool { NSLog(@"Hello, World!"); } } 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. The following code prints the message to standard output without a timestamp using exclusively Objective-C messages: #import <Foundation/Foundation.h> int main() { @autoreleasepool { NSFileHandle *standardOutput = [NSFileHandle fileHandleWithStandardOutput]; NSString *message = @"Hello, World!\n"; [standardOutput writeData:[message dataUsingEncoding:NSUTF8StringEncoding]]; } } 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. #import <Foundation/Foundation.h> int main() { @autoreleasepool { NSString *message = @"Hello, World!\n"; printf("%s", message.UTF8String); } }
Version data entries
10 entries across 7 versions & 1 rubygems