Pages

Friday, June 11, 2010

64-bit Objective-C

On 64-bit you can use properties to generate both accessor methods and the instance variable itself. This code compiles and works on Snow Leopard:
#import <Foundation/Foundation.h>

@interface Test : NSObject
@property (retain) NSString *name;
@end

@implementation Test
@synthesize name;
@end

int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

Test *test = [[Test alloc] init];
[test setName: @"TheName"];
NSLog(@"Name is %@\n", [test name]);
[pool drain];
return 0;
}

Here is the console:

Program loaded.
run
[Switching to process 2963]
Running…
2010-06-12 00:42:30.308 Test64[2963:a0f] Name is TheName

Debugger stopped.
Program exited with status value:0.

No comments:

Post a Comment