views:

79

answers:

4

what is the syntax to use an object (NSString) that declared in another class?

object workId in class works, i want to use it's value in class jobs.

thanks.

+1  A: 

if you declared workId as a property and synthesized it, you should be able to access it using works.workId or [works workId]

http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/ObjectiveC/Articles/ocProperties.html

jmans
i need to declare it also in jobs class ?
dani_au
You shouldn't need to.
jmans
You'll need to import the header for your works class into your jobs class' implementation, so jobs knows about works and what it can do.
Jasarien
+2  A: 

Go here: http://www.cocoadevcentral.com/d/learn%5Fobjectivec/

And scroll down to the "Properties" section.

philfreo
+1  A: 

If you'd like to hold a pointer to the same object you can declare a second property in the Jobs class using 'assign' or 'retain', if you'd just like a copy you could declare the property using 'copy'.

@property(nonatomic, copy) NSString* theString;

If Jobs has a pointer to Works like so:

@interface Jobs 
{
    Works* works;
}
@property (nonatomic, retain) Works* works;
@end

You could just use self.works.workId to access the work id from within an instance of the Jobs class.

Could you let us know a little more about your particular use case, it would help to determine what you should be doing.

jessecurry
A: 

in Person.h:

#import <Foundation/Foundation.h>

@interface Person : NSObject {
    NSString * name;
}
@end

in Person.m:

@implementation Person

- (NSString*) name {
    return name;
}

- (void)setName:(NSString *)aName {
    [name autorelease];
    name = [aName copy];
}

@end
stefanB