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
ajtgarber
Chaos Rift Cool Newbie
Posts: 97 Joined: Wed Jun 10, 2009 8:56 am
Post
by ajtgarber » Thu Jun 17, 2010 8:39 pm
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?
avansc
Respected Programmer
Posts: 1708 Joined: Sun Nov 02, 2008 6:29 pm
Post
by avansc » Thu Jun 17, 2010 9:38 pm
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
Posts: 97 Joined: Wed Jun 10, 2009 8:56 am
Post
by ajtgarber » Fri Jun 18, 2010 10:22 am
Do the setters release the old object?
A Person
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
Post
by A Person » Mon Jul 12, 2010 3:25 am
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