#import <Foundation/Foundation.h> @interface SayHello : NSObject - (void)greet; @end @implementation SayHello - (void)greet { NSLog(@"Hello GnuStep"); } @end int main(int argc, char *argv[]) { NSLog(@"arrayCls = %@", objc_getClass("NSArray")); // Yes NSLog(@"stringCls = %@", objc_getClass("NSString")); // Yes
//! NSLog(@"userCls = %@", [SayHello class]); -- crash here! NSLog(@"userCls = %@", objc_getClass("SayHello")); // null
NSArray *nameList = [NSArray arrayWithObjects: @"Scott", @"Jesse", @"Gaia", nil ]; NSLog(@"nameList = %@", nameList); // good NSArray *nameList2 = [[NSArray alloc] init]; NSLog(@"nameList2 = %@", nameList2); // Ok
SayHello *userObj = [[SayHello alloc] init]; // crash here! NSLog(@"userObj = %@", userObj); return 0; } |