neu in Objective-C,objectC Autorelease-Problem, was ist falsch mit Code?
#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"]);
}
ich Zeitfehler nicht bekommen kompilieren, aber Zeitfehler ausführen ich habe:
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
Sieht aus wie es ist etwas mit dem zu tun Speicherproblem. Einige zeigen das Problem auf?
HINWEIS: Mit allen Eingängen, könnte ich das Autorelease Problem beheben, aber immer noch
NSLog (@" KVC Retrieveal %i ", [t valueForKey:@"x"]);
nicht den richtigen Wert drucken, aber den Müll. Mache ich etwas falsch?
Ihre überarbeitete Frage hat nichts funktioniert mit Ihrer ursprünglichen Frage zu tun. Aber die Antwort ist, dass die Formatzeichenfolge "% i" eine Ganzzahl angibt, während "valueForKey:" ein Objekt zurückgibt. – Chuck