I have used the following code.
MainView.h:
NSString *sCopySource;
NSString *sFileSource;
// retain and copy used both for test proposes
@property (nonatomic, retain) NSString *sCopySource;
@property (nonatomic, copy) NSString *sFileSource;
MainView.m:
// Inside the first method:
sCopySource = [NSString stringWithFormat:@"%@%@", path1, filename];
sFileSource = [NSString stringWithFormat:@"%@%@", path2, filename];
// Inside the second method:
[[NSFileManager defaultManager] copyItemAtPath:sCopySource toPath:sFileSource error:&err];
And take error in the last line of the code by zombie-enabled objects sCopySource and sFileSource:
message sent to deallocated instance
Why? The properties marked as retain and copy. How to fix this?
Thanks a lot for the help!
P.S. Please don’t answer to use ratain and release methods. They’re extremely inconvenient.
You have defined the property, but you are writing directly to the instance variable.
If you want to use the retain/release logic in the property, you need to use:
That way, the methods that do the copy and retain are used.