Nouveau je suis arrivé à Objective-C,objectifC autorelease problème, quel est le problème avec le 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"]);
}
Je n'ai pas erreur de compilation de temps, mais courir erreur de temps:
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
On dirait qu'il ya quelque chose à voir avec problème de mémoire. Quelqu'un souligne le problème?
REMARQUE: Avec toutes vos entrées, je pourrais résoudre le problème de autorelease, mais toujours
NSLog (@" KVC Retrieveal %i ", [t valueForKey:@"x"]);
n'imprime pas la valeur correcte, mais la poubelle. Est-ce que je fais quelque chose de mal?
Votre question révisée n'a rien à voir avec votre question initiale. Mais la réponse est que la chaîne de format "% i" spécifie un entier tandis que 'valueForKey:' renvoie un objet. – Chuck