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];
/* Synthesized Set Method */
[t setX:100];
[t setY:200];
/* Synthesized Get Method */
NSLog (@"Retrieving Values %i, %i ",[t x], [t y]);
/* another Way to retrieve the throuhg KVC Model */
NSLog (@" KVC Retrieveal %i ", [t valueForKey:@"x"]);
}
我没有得到编译时错误,但我得到了运行时错误:
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
看起来这与内存问题有关。有人指出问题?
注意:通过您的所有输入,我可以解决自动释放问题,但仍然
NSLog (@" KVC Retrieveal %i ", [t valueForKey:@"x"]);
不打印正确的值,而是打印垃圾。难道我做错了什么?