1

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.

4 Answers 4

2

Go here: http://www.cocoadevcentral.com/d/learn_objectivec/

And scroll down to the "Properties" section.

Sign up to request clarification or add additional context in comments.

Comments

1

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

2 Comments

i need to declare it also in jobs class ?
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.
1

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.

Comments

0

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 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.