I used the codes below to set a NSString
#import <Foundation/Foundation.h>
@interface AppController : NSObject
{
NSString *myString;
}
@property (nonatomic, retain) NSString *myString;
@end
#import "AppController.h"
@implementation AppController
@synthesize myString;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSString *zs0= [[NSString alloc] initWithFormat: @"abc"];
myString =[zs0 retain];
[zs0 release];//breakpoint
}
- (void)dealloc {
[myString release];
[super dealloc];
}
@end
when I check the value of myString at the breakpoint
it always said ‘out of scope’
Welcome any comment
One simple way is:
That will create a string that’s autoreleased (not created with alloc, copy by convention) and then the property will retain it.