New in objective-C,
#import <objc/objc.h>
#import <Foundation/Foundation.h>
@interface Test:NSObject
{
int x,y, abc;
NSString *v1, *v2;
}
@property int x , y, abc;
-(void) print;
@end
@implementation Test
@synthesize x,y, abc;
-(void) print
{
NSLog (@"v1 and v2 values %i, %i ", v1, v2);
}
@end
int main ( int argc, char **argv)
{
Test *t = [[Test alloc] init];
[t setX:100];
[t setY:200];
NSLog (@"Retrieving Values %i, %i ",[t x], [t y]);
NSLog (@" KVC Retrieveal %i ", [t valueForKey:@"x"]);
}
I did not get a compile-time error, but I got a runtime error:
2012-04-11 16:25:08.470 testpgm[22237] Retrieving Values 100, 200
2012-04-11 16:25:08.513 testpgm[22237] autorelease called without pool for object (0x8e78ca0) of class NSMethodSignature in thread <NSThread: 0x8e23a08>
2012-04-11 16:25:08.514 testpgm[22237] autorelease called without pool for object (0x8e94610) of class NSIntNumber in thread <NSThread: 0x8e23a08>
2012-04-11 16:25:08.514 testpgm[22237] KVC Retrieveal 149505552
This seems to be due to a memory issue. Does anyone point out a problem?
NOTE. . Using all your inputs, I can solve the autorun problem, but still
NSLog (@" KVC Retrieveal %i ", [t valueForKey:@"x"]);
does not print the correct value, but garbage. Am I doing something wrong?
source
share