Objective-C Property Question

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
ajtgarber
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 97
Joined: Wed Jun 10, 2009 8:56 am

Objective-C Property Question

Post 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?
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: Objective-C Property Question

Post by avansc »

retain increases or sets the reference count to 1, not completely sure.
@synthesize just auto produces setters and getters.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
ajtgarber
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 97
Joined: Wed Jun 10, 2009 8:56 am

Re: Objective-C Property Question

Post by ajtgarber »

Do the setters release the old object?
A Person
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 10
Joined: Mon Jul 12, 2010 3:12 am
Current Project: iPhone 2D Game
Favorite Gaming Platforms: Wii, NDS, iPhone, 360
Programming Language of Choice: Objective-C
Location: Calgary, AB

Re: Objective-C Property Question

Post 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
Post Reply