Page 1 of 1

Objective-C Property Question

Posted: Thu Jun 17, 2010 8:39 pm
by ajtgarber
Hello all, right now I'm trying to learn Objective-C so that I can (hopefully) eventually make games for the IPhone.
Right now I'm looking at a tutorial for Objective-C, and I saw this code in it:

Code: Select all

#import <Cocoa/Cocoa.h>

@interface Photo : NSObject {
      NSString* caption;
      NSString* photographer;
}
@property (retain) NSString* caption;
@property (retain) NSString* photographer;

@end
The tutorial says that this will retain the new value, but if you were to @synthesize the two, would it also release caption/photographer?

Re: Objective-C Property Question

Posted: Thu Jun 17, 2010 9:38 pm
by avansc
retain increases or sets the reference count to 1, not completely sure.
@synthesize just auto produces setters and getters.

Re: Objective-C Property Question

Posted: Fri Jun 18, 2010 10:22 am
by ajtgarber
Do the setters release the old object?

Re: Objective-C Property Question

Posted: Mon Jul 12, 2010 3:25 am
by A Person
I don't ever retain my NSStrings but retain just adds +1 to the reference count so as to prevent EXC_BAD_ACCESS because of missing memory